【链接】 我是链接,点我呀:)

【题意】

让你把数组分成k个连续的部分
使得每个部分最大的m个数字的和最大

【题解】

把原数组降序排序
然后选取前m*k个数字打标记
然后对于原数组
一直贪心地取
直到这个区间选了m个打标记的数字为止。
然后就划分一个区间>_

【代码】

  1. import java.io.*;
  2. import java.util.*;
  3. public class Main {
  4. static int N = (int)2e5;
  5. static InputReader in;
  6. static PrintWriter out;
  7. static class Pair implements Comparable<Pair>{
  8. int x,id;
  9. public Pair(int x,int id) {
  10. this.x = x;this.id = id;
  11. }
  12. @Override
  13. public int compareTo(Pair o) {
  14. // TODO Auto-generated method stub
  15. return o.x-this.x;
  16. }
  17. }
  18. public static void main(String[] args) throws IOException{
  19. //InputStream ins = new FileInputStream("E:\\rush.txt");
  20. InputStream ins = System.in;
  21. in = new InputReader(ins);
  22. out = new PrintWriter(System.out);
  23. //code start from here
  24. new Task().solve(in, out);
  25. out.close();
  26. }
  27. static class Task{
  28. public void solve(InputReader in,PrintWriter out) {
  29. int n,m,k;
  30. int []a = new int [N+10];
  31. int []tag = new int [N+10];
  32. Pair []b = new Pair[N+10];
  33. n = in.nextInt();m = in.nextInt();k = in.nextInt();
  34. for (int i = 1;i <= n;i++) a[i] = in.nextInt();
  35. for (int i = 1;i <= n;i++) {
  36. b[i] = new Pair(a[i],i);
  37. }
  38. Arrays.sort(b, 1,n+1);
  39. long ans1 = 0;
  40. for (int i = 1;i <=m*k;i++) {
  41. tag[b[i].id]= 1;
  42. ans1 = ans1 + b[i].x;
  43. }
  44. out.println(ans1);
  45. int cnt = 0;
  46. int cnt2 = 0;
  47. for (int i = 1;i <= n;i++){
  48. if (tag[i]==1) {
  49. cnt++;
  50. if (cnt==m) {
  51. cnt = 0;
  52. out.print(i+" ");
  53. cnt2++;
  54. if (cnt2==k-1){
  55. return;
  56. }
  57. }
  58. }
  59. }
  60. }
  61. }
  62. static class InputReader{
  63. public BufferedReader br;
  64. public StringTokenizer tokenizer;
  65. public InputReader(InputStream ins) {
  66. br = new BufferedReader(new InputStreamReader(ins));
  67. tokenizer = null;
  68. }
  69. public String next(){
  70. while (tokenizer==null || !tokenizer.hasMoreTokens()) {
  71. try {
  72. tokenizer = new StringTokenizer(br.readLine());
  73. }catch(IOException e) {
  74. throw new RuntimeException(e);
  75. }
  76. }
  77. return tokenizer.nextToken();
  78. }
  79. public int nextInt() {
  80. return Integer.parseInt(next());
  81. }
  82. }
  83. }

【Codeforces 1114B】Yet Another Array Partitioning Task的更多相关文章

  1. 【24.17%】【codeforces 721D】Maxim and Array

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  2. 【codeforces 754A】Lesha and array splitting

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  3. 【Codeforces 258B】 Sort the Array

    [题目链接] http://codeforces.com/contest/451/problem/B [算法] 模拟 在序列中找到一段单调递增的子序列,将这段序列反转,然后判断序列是否变得单调递增,即 ...

  4. 【codeforces 719E】Sasha and Array

    [题目链接]:http://codeforces.com/contest/719/problem/E [题意] 给你一个数列,有两种操作1 l r x 给[l,r]区间上的数加上x, 2 l r 询问 ...

  5. 【44.19%】【codeforces 727C】Guess the Array

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  6. 【Codeforces 1042D】Petya and Array

    [链接] 我是链接,点我呀:) [题意] 题意 [题解] 把a[i]处理成前缀和 离散化. 枚举i从1..n假设a[i]是区间和的a[r] 显然我们需要找到a[r]-a[l]<t的l的个数 即a ...

  7. 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 ...

  8. 【codeforces 415D】Mashmokh and ACM(普通dp)

    [codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...

  9. 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 ...

随机推荐

  1. tiny4412学习(四)之移植linux-设备树(1)设备树基础知识及GPIO中断【转】

    本文转载自:http://blog.csdn.net/fengyuwuzu0519/article/details/74177978 版权声明:本文为博主原创文章,转载请注明http://blog.c ...

  2. hdu 6198(矩阵快速幂)

    number number number Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Oth ...

  3. Anaconda 安装和使用Numpy、Scipy、pandas、Scikit-learn

    Anaconda 安装和使用 https://www.cnblogs.com/liruihuan/p/9101613.html 最近看了些关于数据分析的书,想系统的整理下相关知识,算是学习笔记吧,也希 ...

  4. roundabout旋转幻灯

    jquery.roundabout.js文件/** * jQuery Roundabout - v2.4.2 * http://fredhq.com/projects/roundabout * * M ...

  5. POJ3070Fibonacci

    矩阵乘法裸题 求快速幂 #include<iostream> #include<cstdio> #define ll long long #define Mod 10000 u ...

  6. Akka源码分析-Actor创建(续)

    在上一遍博客中,我们已经分析了actor创建的大致过程,但只是涉及到了Dipatcher/Mailbox/ActorCell/InternalActorRef等对象的创建,并没有介绍我们自定义的继承A ...

  7. centos安装 memcached

    .安装 yum -y update yum install -y libevent libevent-devel yum install -y memcached 2.配置 vi /etc/sysco ...

  8. ACM算法目录

    数据结构 栈,队列,链表 •哈希表,哈希数组 •堆,优先队列 双端队列 可并堆 左偏堆 •二叉查找树 Treap 伸展树 •并查集 集合计数问题 二分图的识别 •平衡二叉树 •二叉排序树 •线段树 一 ...

  9. 注解配置AOP切面编程

    1.导入先关jar包 2.编写applicationContext.xml,配置开启注解扫描和切面注解扫描 <?xml version="1.0" encoding=&quo ...

  10. MySQL的DML和DQL 增删改查

    DML和DQL   增删改查 SELECT * FROM grade --新增 insert -- 向年级表中新增3条数据INSERT INTO grade(gradeID,gradeName) VA ...