Codeforces Round #339 (Div. 2) D. Skills
来源:互联网 发布:fbx sdk编程指南 编辑:程序博客网 时间:2024/06/11 12:59
Lesha plays the recently published new version of the legendary game hacknet. In this version character skill mechanism was introduced. Now, each player character has exactlyn skills. Each skill is represented by a non-negative integerai — the current skill level. All skills have the same maximum levelA.
Along with the skills, global ranking of all players was added. Players are ranked according to the so-called Force. TheForce of a player is the sum of the following values:
- The number of skills that a character has perfected (i.e., such thatai = A), multiplied by coefficient cf.
- The minimum skill level among all skills (min ai), multiplied by coefficient cm.
Now Lesha has m hacknetian currency units, which he is willing to spend. Each currency unit can increase the current level of any skill by 1 (if it's not equal toA yet). Help him spend his money in order to achieve the maximum possible value of the Force.
The first line of the input contains five space-separated integersn,A,cf,cm andm (1 ≤ n ≤ 100 000,1 ≤ A ≤ 109,0 ≤ cf, cm ≤ 1000,0 ≤ m ≤ 1015).
The second line contains exactly n integersai (0 ≤ ai ≤ A), separated by spaces, — the current levels of skills.
On the first line print the maximum value of the Force that the character can achieve using no more thanm currency units.
On the second line print n integersa'i (ai ≤ a'i ≤ A), skill levels which one must achieve in order to reach the specified value of the Force, while using no more thanm currency units. Numbers should be separated by spaces.
3 5 10 1 51 3 1
122 5 2
3 5 10 1 3391 3 1
355 5 5
In the first test the optimal strategy is to increase the second skill to its maximum, and increase the two others by1.
In the second test one should increase all skills to maximum.
题意:第一行告诉你5个数n,A,cf,cm,m;
第二行为n个数;
让你对这些数进行操作,每次操作可以把一个数加1,操作数不超过m,并且每个数不超过A。现在记操作后最大的数A的个数为maxNum,最小的值为minval,让你求maxNum*cf+minval*cm的最大值。
分析:我们可以通过确定最大数A的个数,让后把其余的操作数留给最小值,确定最小值时不能瞎暴力,提示一下:假使现在有num个最小值minval,剩余操作数为M,那么这num个数要一起向上加(因为只顾一个的话最小值还是不会变,都变了最小值才会改变),所以最小值可以变为minval+M/num;这个还是很好理解的。此题还需要各种细节,好的姿势才会敲得轻松,不在累述。
#include<stdio.h>#include<string.h>#include<algorithm>#define LL long longusing namespace std;struct node{ LL num,id;///记录值和位置,方便最后输出结果}a[100010];bool cmp1(node x,node y)///让num从大到小排列{ return x.num>y.num;}bool cmp2(node x,node y)///输出结果时用{ return x.id<y.id;}LL sum[100010],ne[100010],need[100010];int main(){ LL n,A,cf,cm,m; while(scanf("%lld%lld%lld%lld%lld",&n,&A,&cf,&cm,&m)!=EOF) { for(LL i=1;i<=n;i++) { scanf("%lld",&a[i].num); a[i].id=i; } sort(a+1,a+n+1,cmp1); sum[0]=0; for(LL i=1;i<=n;i++) sum[i]=sum[i-1]+A-a[i].num;///预处理前i个数填满到A需要多少次 ne[n]=0; for(LL i=n-1;i>=1;i--) ne[i]=ne[i+1]+(a[i].num-a[i+1].num)*(n-i);///假如当前数为num,要把比它小的所有数填到num这个数那么多需要ne[i]次 for(LL i=1;i<=n;i++) need[i]=ne[n-i+1];///这里只是为了二分查找而反过来了,要不然是递减序列 LL ans=-1,minval,minnum,maxnum; for(LL i=0;i<=n;i++) { LL M=m; if(sum[i]>M) break; if(i==n)///特殊处理全为A的情况 { LL tem=n*cf+A*cm; if(ans<tem) { ans=tem; minnum=n; minval=A; maxnum=n; } break; } M-=sum[i]; LL pos=upper_bound(need+1,need+n+1,M)-need; pos--; if(pos>=n-i) { LL x=n-i; M-=need[x]; LL y=a[i+1].num+M/x; LL tem=i*cf+min(y,A)*cm;///取min是保证不大于A而已 if(tem>ans) { maxnum=i; ans=tem; minnum=x; minval=min(y,A); } } else { LL x=pos; M-=need[pos]; LL y=a[n-pos+1].num+M/x; LL tem=i*cf+y*cm; if(tem>ans) { maxnum=i; ans=tem; minnum=x; minval=y; } } } printf("%lld\n",ans); for(LL i=1;i<=maxnum;i++) a[i].num=A;///前maxnum个数都为A for(LL i=n;i>=n-minnum+1;i--) a[i].num=minval;///最后minnum个数为minval sort(a+1,a+n+1,cmp2); for(LL i=1;i<n;i++) printf("%lld ",a[i].num); printf("%lld\n",a[n].num); } return 0;}
- Codeforces Round #339 (Div. 2)D. Skills
- Codeforces Round #339 (Div. 2) D. Skills
- Codeforces Round #339 (Div. 2) D. Skills
- Codeforces Round #339 (Div. 2) D. Skills(模拟+枚举)
- Codeforces Round #339 (Div. 2) D.Skills(贪心)
- Codeforces Round #339 (Div. 2)D. Skills(二分)
- Codeforces Round #339 (Div. 2)-D-Skills(二分)
- Codeforces Round #339 D. Skills
- Codeforces Round #339 (Div. 2) D .Skills 偷师一波前缀和的运用
- 【贪心】Codeforces Round #339 (Div. 2) D
- Codeforces Round #322 (Div. 2)C. Developing Skills
- Codeforces Round #322 (Div. 2)C. Developing Skills
- 【Codeforces Round 339 (Div 2)D】【暴力 贪心 二分】Skills 最高技能人数乘cm+最低技能乘cf权值最大
- Codeforces Round #339 (Div. 2) (A,B,C,D)
- Codeforces Round #103 (Div. 2) D
- Codeforces Round #104 (Div. 2) D
- Codeforces Round #105 (Div. 2) D
- Codeforces Round #139 (Div. 2) D. Snake
- android基础夯实2
- SDK Hello world
- HTML中怎么设置图片的位置和大小
- eclipse maven工程导入到MyEclipse出现"Versions of Spring facet could not be detected”的解决方法
- 性能测试项
- Codeforces Round #339 (Div. 2) D. Skills
- Cocos2d-js windows 下环境搭建与调试(一)
- 【Web前端】:JavaScript常用代码积累
- 安装Android adb驱动
- 读书笔记 JavaScript 高级程序设计(第三版)-- 第2章
- android-IPC进程间通信
- 抽样 拉希里法的变形(Lahiri)
- js 导出excle之终极攻略(兼容各大浏览器),纯JS实现
- sh脚本监控网站状态