【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 ...
随机推荐
- bzoj1805: [Ioi2007]Sail 船帆
可以发现旗杆的顺序是没有用的,对于每列,它的答案是它的最大值mx*(mx+1)/2 高度由小到大排序旗杆,问题可以转化为在前h行选k个最小的值 考虑激情splay乱搞(我只会splay......) ...
- [LeetCode] Unique Binary Search Tree
Given n, how many structurally unique BST's (binary search trees) that store values 1...n? For examp ...
- 【关键字】volatile
volatile 修饰的关键字,确保编译器不对成员变量进行任何优化: private volatile double d; // No optimization
- bzoj4668
并查集+最小生成树 首先我们发现这题可以lct维护最小生成树,但是发现如果生成树在之后是不会修改的,那么就想到了并查集,然后就不知道怎么做了... 其实当我们连接两个连通块的时候,两个连通块只能通过这 ...
- 【WIP】Bootstrap 基础
创建: 2017/09/28 更新: 2017/10/14 标题加上[WIP]
- DFS之城堡问题
2019-06-01 17:54:51 坚持!! 题目链接: http://bailian.openjudge.cn/practice/2815 #include <bits/stdc++.h& ...
- WP8开发常用解决方案收集
我其实不怎么做wp的东西.但是偶尔还是会用到, 但是wp8开发的资料确实难找.特开此贴,记录一些常见的解决方案 1.水平滑动动画(比如app首次使用说明就可以用这个做) http://www.cnbl ...
- Kibana里No Marvel Data Found问题解决(图文详解)
问题详情 http://192.168.80.145:5601/app/marvel#/no-data?_g=(refreshInterval:(display:'10%20seconds',paus ...
- synchronized关键字详解(二)
synchronized关键字的性质 1.可重入:同一线程的外层函数获得锁之后,内层函数可直接再次获得该锁,好处:避免死锁,提升封装性 证明可重入粒度:1.同一个方法是可重入的 2.可重入不要求是同一 ...
- Android项目实战_手机安全卫士流量统计
## 1.抽屉控件SlidingDrawer:一定要配置android:handle(把手)和android:content(内容),并在子View中添加把手和内容的布局```java <Sli ...