Codeforces Round #339 (Div. 2)D. Skills
来源:互联网 发布:apache tomcat9.0安装 编辑:程序博客网 时间:2024/06/06 20:05
D. Skills
time limit per test2 seconds
memory limit per test256 megabytes
inputstandard input
outputstandard output
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 exactly n skills. Each skill is represented by a non-negative integer ai — the current skill level. All skills have the same maximum level A.
Along with the skills, global ranking of all players was added. Players are ranked according to the so-called Force. The Force of a player is the sum of the following values:
The number of skills that a character has perfected (i.e., such that ai = 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 to A yet). Help him spend his money in order to achieve the maximum possible value of the Force.
Input
The first line of the input contains five space-separated integers n, A, cf, cm and m (1 ≤ n ≤ 100 000, 1 ≤ A ≤ 109, 0 ≤ cf, cm ≤ 1000, 0 ≤ m ≤ 1015).
The second line contains exactly n integers ai (0 ≤ ai ≤ A), separated by spaces, — the current levels of skills.
Output
On the first line print the maximum value of the Force that the character can achieve using no more than m currency units.
On the second line print n integers a’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 than m currency units. Numbers should be separated by spaces.
Sample test(s)
input
3 5 10 1 5
1 3 1
output
12
2 5 2
input
3 5 10 1 339
1 3 1
output
35
5 5 5
Note
In the first test the optimal strategy is to increase the second skill to its maximum, and increase the two others by 1.
In the second test one should increase all skills to maximum.
记最小值ansmin,最小值个数ansi, perfect个数per_cnt;
ans=per_cnt*cf+ansmin*cm;
可以想到枚举perfect个数,剩余价值用来提高最小值ansmin.
#include<cstdio>#include<iostream>#include<algorithm>#include<queue>#include<set>#include<vector>#include<math.h>#include<string.h>using namespace std;#define LL __int64#define N 100005struct node{ int val,id;}a[N];LL s[N];bool cmp1(node a,node b){ return a.val<b.val;}bool cmp2(node a,node b) { return a.id<b.id;}int main(){ int i,j,n,A,cf,cm; LL m; while(~scanf("%d%d%d%d%I64d",&n,&A,&cf,&cm,&m)){ for(i=0;i<n;++i){ scanf("%d",&a[i].val); a[i].id=i; } sort(a,a+n,cmp1); //按值大小排序,非递减 s[0]=0; //初始化累加和 for(i=0;i<n;++i){ s[i+1]=s[i]+a[i].val; } LL ans=-1,ansi,ansj,ansmin; LL cost,tmp,tmin,left; for(i=0,j=0;i<=n;++i){ //有几个值改变为perfect,i取值范围[0,n] cost=(LL)A*(n-i)-(s[n]-s[i]); if(cost>m) continue; tmp=(n-i)*cf; left=m-cost; while(j<i&&(LL)a[j].val*j-s[j]<=left){ ++j; //判断{a[0].val,...,a[j-1].val}这j个值加上剩余价值left,能否达到a[j].val } //如果可以达到,则{0,...,j-1,j},共(j+1)个值至少为a[j].val; if(j==0){ //最后一步为++j,此时的j为(j_pre+1) tmin=A; } else{ tmin=min((left+s[j])/j,(LL)A); //最小值<=A } tmp+=(LL)tmin*cm; if(ans<tmp){ ans=tmp; ansi=i; //[i,n-1]为perfect ansj=j-1; //[0,j-1]为最小值tmin; ansmin=tmin; } } for(i=ansi;i<n;++i){ a[i].val=A; } for(i=0;i<=ansj;++i){ a[i].val=ansmin; } sort(a,a+n,cmp2); cout<<ans<<endl; for(i=0;i<n;++i){ printf("%d ",a[i].val); } puts(""); } 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
- JSTL---Servlet.service() for servlet action threw exceptionjavax.el.MethodNotFoundException Method s
- error C4013: 'RtlStringCbPrintf' undefined; assuming extern returning int
- Uva1629:Cake slicing
- jenkins+maven+svn构建项目,及远程部署war包到tomcat上
- [Leetcode]10. Regular Expression Matching @python
- Codeforces Round #339 (Div. 2)D. Skills
- 【转】图解HTTPS
- JVM学习笔记(六)--- 垃圾回收面临的问题
- http-关于content-type等字符编码的解释说明
- poj DNA Sorting
- 214,使用storyboard实现页面跳转
- 菜单展开缩放联动
- error LNK2019: unresolved externalsymbol _RtlStringVPrintfWorkerA@20 referenced in function _RtlStri
- SpringMVC返回文件流