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.

简单题意

你有n个技能可以学,你有m个技能点可以分配,每个技能的上限值都是A,每个技能都给出了至少要学的等级,然后你要合理分配技能点,使得战力最大

战力=满级技能*Cf+最小等级*Cm

然后我们枚举满级的技能个数,显然我们应该把那些至少学习等级大的点成满级,然后剩下的技能尽量最小等级最大

所以我们一开始从小到大排序,枚举后面i个变成满级,前面的二分最小等级,用前缀和判断可行性,然后计算出战力,更新答案

 #include<cstdio>
#include<algorithm>
using namespace std; const int maxn=; long long A,cf,cm,n,w,a[maxn],b[maxn],s[maxn],ans,tmp1,tmp2; bool compare(long long x,long long y){
return a[x]<a[y];
} long long find(long long x,long long rr){
long long l,r,mid;
l=;r=rr;
while(l!=r){
mid=(l+r+)/;
if(a[b[mid]]<x)l=mid;
else r=mid-;
}
return l;
} int main(){
scanf("%I64d%I64d%I64d%I64d%I64d",&n,&A,&cf,&cm,&w);
long long i;
for(i=;i<=n;i++)scanf("%I64d",&a[i]);
for(i=;i<=n;i++)b[i]=i;
sort(b+,b++n,compare);
for(i=;i<=n;i++)s[i]=s[i-]+a[b[i]];
w+=s[n];
ans=-;
for(i=;i<=n+;i++){
if(A*(n-i+)+s[i-]>w)continue;
if(i==)ans=cf*n+cm*A,tmp1=;
if(i==)break;
long long l=a[b[]],r=A,mid,tt;
while(l!=r){
mid=(l+r+)/;
tt=find(mid,i-);
if(A*(n+-i)+mid*tt+s[i-]-s[tt]<=w)l=mid;
else r=mid-;
}
if(ans<cf*(n+-i)+l*cm)ans=cf*(n+-i)+l*cm,tmp1=i,tmp2=l;
}
printf("%I64d\n",ans);
for(i=;i<tmp1;i++)
if(a[b[i]]<tmp2)a[b[i]]=tmp2;
for(i=tmp1;i<=n;i++)a[b[i]]=A;
for(i=;i<=n;i++)printf("%I64d ",a[i]);
return ;
}

AC代码

Skills - CF613B的更多相关文章

  1. CF613B Skills

    CF613B Skills 洛谷评测传送门 题目描述 Lesha plays the recently published new version of the legendary game hack ...

  2. How to Develop blade and soul Skills

    How to Develop Skills Each skill can be improved for variation effects. Some will boost more strengt ...

  3. Top Five Communication Skills for Project Managers

    Research among project managers globally identifies top communication skills for leading teams. Lead ...

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

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

  5. Computer skills one can learn within one day

    Computer related technical skills are usually thought as complicated and difficult to understand. It ...

  6. Advice on improving your programming skills

    Programming is cool. But behind the scenes it's also difficult for many people. Many people are defe ...

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

  8. cf581C Developing Skills

    Petya loves computer games. Finally a game that he's been waiting for so long came out! The main cha ...

  9. What skills are needed for machine learning jobs

    What skills are needed for machine learning jobs?机器学习工作必须技能 原文: http://www.quora.com/Machine-Learnin ...

随机推荐

  1. 北京Uber优步司机奖励政策(1月16日)

    滴快车单单2.5倍,注册地址:http://www.udache.com/ 如何注册Uber司机(全国版最新最详细注册流程)/月入2万/不用抢单:http://www.cnblogs.com/mfry ...

  2. 12 垃圾回收GC

    1.垃圾回收 1.) 小整数对象池    #提前建立好的 Python 对小整数的定义是 [-5, 257) 这些整数对象是提前建立好的,不会被垃圾回收.在一个 Python 的程序中,所有位于这个范 ...

  3. dubbo之监控中心(monitor)

    一.monitor是dubbo框架中的一个监控中心.这个只是针对于消费者和提供者进行一个数据记录,不参与业务和使用.当然当monitor挂掉之后,也不会影响服务的正常运行. 二.在阿里的dubbo中也 ...

  4. cf#516C. Oh Those Palindromes(最多回文子串的字符串排列方式,字典序)

    http://codeforces.com/contest/1064/problem/C 题意:给出一个字符串,要求重新排列这个字符串,是他的回文子串数量最多并输出这个字符串. 题解:字典序排列的字符 ...

  5. VIN码识别(车架号识别)在二手车交易中的应用

    最新数据统计,2015年,中国卖出2110万辆新车,相比之下,美国卖出去了1740辆新车.然而,如果算上二手车,美国的汽车市场销量将扩展到4000多辆,而中国的乘用车才不到3000万辆. 销售总额上, ...

  6. 爬虫1.1-基础知识+requests库

    目录 爬虫-基础知识+requests库 1. 状态返回码 2. URL各个字段解释 2. requests库 3. requests库爬虫的基本流程 爬虫-基础知识+requests库 关于html ...

  7. chorme打开网页的技巧

    恢复之前关闭的网页 ctr l+ shift + t 打开之前不小心关闭的网页 临时书签 在设置书签中有 为打开的网页添加书签 的选项, 清除地址栏搜索记录 首先需要退出个人谷歌账户,账户上的搜索记录 ...

  8. 技本功丨知否知否,Redux源码竟如此意味深长(上集)

    夫 子 说 元月二号欠下袋鼠云技术公号一篇关于Redux源码解读的文章,转眼月底,期间常被“债主”上门催债.由于年底项目工期比较紧,于是债务就这样被利滚利.但是好在这段时间有点闲暇,于是赶紧把这篇文章 ...

  9. 关于C#中如何使用wmi获得操作系统信息?

    最近项目中用到了windows server 2012操作系统中的存储池和ISCSI Disk的技术.前期,我们整个操作都是用power shell脚本去实现了.带来了不方便,后期要使用wmi API ...

  10. 索引值迭代-enumerate

    你想在迭代一个序列的同时跟踪正在被处理的元素索引?内置的enumerate() 函数可以很好的解决这个问题: list_c = ['a', 'b', 'c'] for i, c in enumerat ...