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. 【BZOJ2286】消耗战(虚树,动态规划)

    [BZOJ2286]消耗战(虚树,动态规划) 题面 BZOJ Description 在一场战争中,战场由n个岛屿和n-1个桥梁组成,保证每两个岛屿间有且仅有一条路径可达.现在,我军已经侦查到敌军的总 ...

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

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

  3. Nodejs中的流

    Nodejs中的很多地方都用到了流,流是一个很常见的概念,一个http请求,控制台输入输出的形式都是流.流可以分为三种: 可读流 可写流 既能读又能写 其中第三种流又可以分为全双工流Duplex和转换 ...

  4. P3379 【模板】最近公共祖先(LCA)

    P3379 [模板]最近公共祖先(LCA) 题目描述 如题,给定一棵有根多叉树,请求出指定两个点直接最近的公共祖先. 输入输出格式 输入格式: 第一行包含三个正整数N.M.S,分别表示树的结点个数.询 ...

  5. getSteam

    using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using Sy ...

  6. Linux tcpdump命令详解(分享文章)

    简介 用简单的话来定义tcpdump,就是:dump the traffic on a network,根据使用者的定义对网络上的数据包进行截获的包分析工具. tcpdump可以将网络中传送的数据包的 ...

  7. 基于Kafka的服务端用户行为日志采集

    本文来自网易云社区 作者:李勇 背景 随着互联网的不断发展,用户所产生的行为数据被越来越多的网站重视,那么什么是用户行为呢?所谓的用户行为主要由五种元素组成:时间.地点.人物.行为.行为对应的内容.为 ...

  8. mysql数据库目录存放位置更改

    http://haowen.blog.51cto.com/3486731/1274721 mysql数据库存储路径更改 使用了VPS一段时间之后发现磁盘空间快满了.本人的VPS在购买的时候买了500g ...

  9. lesson 15 Fifty pence worth of trouble

    lesson 15 Fifty pence worth of trouble appreciate =be grateful for We really appreciate all the help ...

  10. 关于html2canvas清晰度

    最近有个小项目 需要生成海报让用户去分享~~~vue做的,海报通过html2canvas 生成. 遇到的最大问题是生成图片的清晰度~~网上找了好多方法. 放大倍数!~网上找的~~ var cntEle ...