排序+枚举+二分

最大的那些变成A,小的那部分提高最小值

  1. #include<cstdio>
  2. #include<cstring>
  3. #include<cmath>
  4. #include<algorithm>
  5. using namespace std;
  6.  
  7. const int maxn=+;
  8. int n;
  9. long long A,cf,cm,m;
  10. struct X
  11. {
  12. long long a;
  13. long long ans;
  14. int id;
  15. } s[maxn];
  16. long long sum[maxn];
  17.  
  18. bool cmp1(const X&a,const X&b)
  19. {
  20. return a.a<b.a;
  21. }
  22.  
  23. bool cmp2(const X&a,const X&b)
  24. {
  25. return a.id<b.id;
  26. }
  27.  
  28. int main()
  29. {
  30. scanf("%d%lld%lld%lld%lld",&n,&A,&cf,&cm,&m);
  31. for(int i=; i<=n; i++)
  32. {
  33. scanf("%lld",&s[i].a);
  34. s[i].id=i;
  35. s[i].ans=s[i].a;
  36. }
  37. sort(s+,s++n,cmp1);
  38. memset(sum,,sizeof sum);
  39. for(int i=; i<=n; i++) sum[i]=sum[i-]+s[i].a;
  40. int ansPos1=,ansPos2=;
  41. long long Max=-;
  42. long long ave=;
  43. for(int i=; i<=n; i++) //最后i个都变成A
  44. {
  45. long long cost=A*i-(sum[n]-sum[n-i]);//最后i个都变成A需要的费用
  46. if(cost>m) break;// 如果费用超过了m,则结束
  47.  
  48. cost=m-cost;//剩余的费用
  49. int left=,right=n-i;//二分查找的范围
  50. int pos=;
  51. while(left<=right)
  52. {
  53. int mid=(left+right)/;
  54. if(mid*s[mid].a-sum[mid]<=cost)
  55. {
  56. pos=mid;
  57. left=mid+;
  58. }
  59. else right=mid-;
  60. }
  61. long long q;
  62. if(pos!=) q=min(A,(cost-pos*s[pos].a+sum[pos])/pos+s[pos].a);
  63. else q=A;
  64. if(q*cm+i*cf>Max)
  65. {
  66. Max=q*cm+i*cf;
  67. ansPos1=pos;
  68. ansPos2=i;
  69. ave=q;
  70. }
  71. }
  72.  
  73. for(int i=n;i>=n-ansPos2+;i--) s[i].ans=A;
  74. for(int i=;i<=ansPos1;i++) s[i].ans=ave;
  75.  
  76. printf("%lld\n",Max);
  77. sort(s+,s+n+,cmp2);
  78. for(int i=;i<=n;i++)
  79. {
  80. printf("%lld",s[i].ans);
  81. if(i<n) printf(" ");
  82. else printf("\n");
  83. }
  84. return ;
  85. }

CodeForces 614D Skills的更多相关文章

  1. [CodeForces - 614D] D - Skills

    D - Skills Lesha plays the recently published new version of the legendary game hacknet. In this ver ...

  2. Skills CodeForces - 614D (贪心)

    链接 大意: $n$门课, 第$i$门分数$a_i$, 可以增加共$m$分, 求$cnt_{mx}*cf+mi*cm$的最大值 $cnt_{mx}$为满分的科目数, $mi$为最低分, $cf$, $ ...

  3. 「日常训练」Skills(Codeforce Round #339 Div.2 D)

    题意(CodeForces 614D) 每个人有\(n(n\le 10^5)\)个技能,技能等级都在\([0,10^9]\)的范围,每个技能有一个当前等级,所有技能的最高等级都为A.一个人的力量被记做 ...

  4. Codeforces Round #322 (Div. 2) C. Developing Skills 优先队列

    C. Developing Skills Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/581/p ...

  5. Codeforces Round #339 (Div. 1) B. Skills 暴力 二分

    B. Skills 题目连接: http://www.codeforces.com/contest/613/problem/B Description Lesha plays the recently ...

  6. codeforces 581C. Developing Skills 解题报告

    题目链接:http://codeforces.com/problemset/problem/581/C 题目意思:给出 n 个数:a1, a2, ..., an (0 ≤ ai ≤ 100).给出值 ...

  7. codeforces 613B B. Skills(枚举+二分+贪心)

    题目链接: B. Skills time limit per test 2 seconds memory limit per test 256 megabytes input standard inp ...

  8. 【CodeForces 613B】Skills

    题 题意 给你n个数,可以花费1使得数字+1,最大加到A,最多花费m.最后,n个数里的最小值为min,为A的有k个,给你cm和cf,求force=min*cm+k*cf 的最大值,和n个数操作后的结果 ...

  9. Skills CodeForces - 613B (双指针)

    大意: $n$门课, 第$i$门分数$a_i$, 可以增加共$m$分, 求$cnt_{mx}*cf+mi*cm$的最大值 $cnt_{mx}$为满分的科目数, $mi$为最低分, $cf$, $cm$ ...

随机推荐

  1. angular、bootstrap初稿搭建

    1.bootstrap3.0中,ie8不兼容响应式设计 @media,需要添加如下2个查件 <!-- html5.js for IE less than 9 -->     <!-- ...

  2. dip2px

    package com.itheima.zhbj.utils; import android.content.Context; public class DensityUtils { public s ...

  3. pci 相关资料

    1.http://www.cnblogs.com/image-eye/archive/2012/02/15/2352699.html

  4. (UE4) 动态加载DLL

    目前还没有实现,实在搞不懂为什么,大概代码如下: //------------------------------------------------------------------------- ...

  5. C#后台绑定ComboBox

    C# using System; using System.Collections.Generic; using System.Linq; using System.Text; using Syste ...

  6. 【滚动数组】 dp poj 1036

    题意:一群匪徒要进入一个酒店.酒店的门有k+1个状态,每个匪徒的参数是:进入时间,符合的状态,携带的钱. 酒店的门刚开始状态0,问最多这个酒店能得到的钱数. 思路: dp数组为DP[T][K]. 转移 ...

  7. ligerUI调用$.ligerDialog.open弹出窗口,关闭后无法获取焦点问题

    1:调用父窗口某一个文件框,获取焦点,   parent.window.document.getElementByIdx_x("roleName").focus(); 2:关闭父窗 ...

  8. OpenGL一些函数详解(二)

    OpenGL ES顶点数据绘制技巧 在OpenGL中,绘制一个长方体,需要将每个顶点的坐标放在一个数组中.保存坐标时有一些技巧(由于字母下标不好表示,因此将下标表示为单引号,如A1将在后文中表示为A' ...

  9. UVALive 2324 Human Gene Functions(动态规划)

    题意:求出将两个字符串改成一样长度所能形成最大的相似度. 思路:这个可以说是编辑距离的一个变形,编辑距离最终状态时要两个字符串完全一致,这个就是要求长度一样,而且这个只允许插入“—”这一个字符.模仿编 ...

  10. android ScrollView嵌套EditText

    editext.setOnTouchListener(new OnTouchListener() {                        @Override            publi ...