【Codeforces 1114B】Yet Another Array Partitioning Task
【链接】 我是链接,点我呀:)
【题意】
让你把数组分成k个连续的部分
使得每个部分最大的m个数字的和最大
【题解】
把原数组降序排序
然后选取前m*k个数字打标记
然后对于原数组
一直贪心地取
直到这个区间选了m个打标记的数字为止。
然后就划分一个区间>_
【代码】
import java.io.*;
import java.util.*;
public class Main {
static int N = (int)2e5;
static InputReader in;
static PrintWriter out;
static class Pair implements Comparable<Pair>{
int x,id;
public Pair(int x,int id) {
this.x = x;this.id = id;
}
@Override
public int compareTo(Pair o) {
// TODO Auto-generated method stub
return o.x-this.x;
}
}
public static void main(String[] args) throws IOException{
//InputStream ins = new FileInputStream("E:\\rush.txt");
InputStream ins = System.in;
in = new InputReader(ins);
out = new PrintWriter(System.out);
//code start from here
new Task().solve(in, out);
out.close();
}
static class Task{
public void solve(InputReader in,PrintWriter out) {
int n,m,k;
int []a = new int [N+10];
int []tag = new int [N+10];
Pair []b = new Pair[N+10];
n = in.nextInt();m = in.nextInt();k = in.nextInt();
for (int i = 1;i <= n;i++) a[i] = in.nextInt();
for (int i = 1;i <= n;i++) {
b[i] = new Pair(a[i],i);
}
Arrays.sort(b, 1,n+1);
long ans1 = 0;
for (int i = 1;i <=m*k;i++) {
tag[b[i].id]= 1;
ans1 = ans1 + b[i].x;
}
out.println(ans1);
int cnt = 0;
int cnt2 = 0;
for (int i = 1;i <= n;i++){
if (tag[i]==1) {
cnt++;
if (cnt==m) {
cnt = 0;
out.print(i+" ");
cnt2++;
if (cnt2==k-1){
return;
}
}
}
}
}
}
static class InputReader{
public BufferedReader br;
public StringTokenizer tokenizer;
public InputReader(InputStream ins) {
br = new BufferedReader(new InputStreamReader(ins));
tokenizer = null;
}
public String next(){
while (tokenizer==null || !tokenizer.hasMoreTokens()) {
try {
tokenizer = new StringTokenizer(br.readLine());
}catch(IOException e) {
throw new RuntimeException(e);
}
}
return tokenizer.nextToken();
}
public int nextInt() {
return Integer.parseInt(next());
}
}
}
【Codeforces 1114B】Yet Another Array Partitioning Task的更多相关文章
- 【24.17%】【codeforces 721D】Maxim and Array
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- 【codeforces 754A】Lesha and array splitting
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- 【Codeforces 258B】 Sort the Array
[题目链接] http://codeforces.com/contest/451/problem/B [算法] 模拟 在序列中找到一段单调递增的子序列,将这段序列反转,然后判断序列是否变得单调递增,即 ...
- 【codeforces 719E】Sasha and Array
[题目链接]:http://codeforces.com/contest/719/problem/E [题意] 给你一个数列,有两种操作1 l r x 给[l,r]区间上的数加上x, 2 l r 询问 ...
- 【44.19%】【codeforces 727C】Guess the Array
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
- 【Codeforces 1042D】Petya and Array
[链接] 我是链接,点我呀:) [题意] 题意 [题解] 把a[i]处理成前缀和 离散化. 枚举i从1..n假设a[i]是区间和的a[r] 显然我们需要找到a[r]-a[l]<t的l的个数 即a ...
- CF#538(div2) B. Yet Another Array Partitioning Task 【YY】
任意门:http://codeforces.com/contest/1114/problem/B B. Yet Another Array Partitioning Task time limit p ...
- 【codeforces 415D】Mashmokh and ACM(普通dp)
[codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...
- B. Yet Another Array Partitioning Task ——cf
B. Yet Another Array Partitioning Task time limit per test 2 seconds memory limit per test 256 megab ...
随机推荐
- tiny4412学习(四)之移植linux-设备树(1)设备树基础知识及GPIO中断【转】
本文转载自:http://blog.csdn.net/fengyuwuzu0519/article/details/74177978 版权声明:本文为博主原创文章,转载请注明http://blog.c ...
- hdu 6198(矩阵快速幂)
number number number Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Oth ...
- Anaconda 安装和使用Numpy、Scipy、pandas、Scikit-learn
Anaconda 安装和使用 https://www.cnblogs.com/liruihuan/p/9101613.html 最近看了些关于数据分析的书,想系统的整理下相关知识,算是学习笔记吧,也希 ...
- roundabout旋转幻灯
jquery.roundabout.js文件/** * jQuery Roundabout - v2.4.2 * http://fredhq.com/projects/roundabout * * M ...
- POJ3070Fibonacci
矩阵乘法裸题 求快速幂 #include<iostream> #include<cstdio> #define ll long long #define Mod 10000 u ...
- Akka源码分析-Actor创建(续)
在上一遍博客中,我们已经分析了actor创建的大致过程,但只是涉及到了Dipatcher/Mailbox/ActorCell/InternalActorRef等对象的创建,并没有介绍我们自定义的继承A ...
- centos安装 memcached
.安装 yum -y update yum install -y libevent libevent-devel yum install -y memcached 2.配置 vi /etc/sysco ...
- ACM算法目录
数据结构 栈,队列,链表 •哈希表,哈希数组 •堆,优先队列 双端队列 可并堆 左偏堆 •二叉查找树 Treap 伸展树 •并查集 集合计数问题 二分图的识别 •平衡二叉树 •二叉排序树 •线段树 一 ...
- 注解配置AOP切面编程
1.导入先关jar包 2.编写applicationContext.xml,配置开启注解扫描和切面注解扫描 <?xml version="1.0" encoding=&quo ...
- MySQL的DML和DQL 增删改查
DML和DQL 增删改查 SELECT * FROM grade --新增 insert -- 向年级表中新增3条数据INSERT INTO grade(gradeID,gradeName) VA ...