题目链接:

B. Skills

time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

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

 
Examples
 
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 题意: m次操作,每次可以任选一个a[i]++,最后要求min(a[i])*cm+num(a[i]==A)*cf最大; 思路: 先排序,再枚举a[i]==A的个数,然后二分min(a[i]),根据贪心的原则,要使num尽量多,那么应该从最大的a[i]开始变成A,要使min(a[i])尽可能大,那么应该把最小的++; AC代码:
//#include <bits/stdc++.h>
#include <vector>
#include <iostream>
#include <queue>
#include <cmath>
#include <map>
#include <cstring>
#include <algorithm>
#include <cstdio> using namespace std;
#define Riep(n) for(int i=1;i<=n;i++)
#define Riop(n) for(int i=0;i<n;i++)
#define Rjep(n) for(int j=1;j<=n;j++)
#define Rjop(n) for(int j=0;j<n;j++)
#define mst(ss,b) memset(ss,b,sizeof(ss));
typedef long long LL;
template<class T> void read(T&num) {
char CH; bool F=false;
for(CH=getchar();CH<''||CH>'';F= CH=='-',CH=getchar());
for(num=;CH>=''&&CH<='';num=num*+CH-'',CH=getchar());
F && (num=-num);
}
int stk[], tp;
template<class T> inline void print(T p) {
if(!p) { puts(""); return; }
while(p) stk[++ tp] = p%, p/=;
while(tp) putchar(stk[tp--] + '');
putchar('\n');
} const LL mod=1e9+;
const double PI=acos(-1.0);
const LL inf=1e14;
const int N=1e5+; int n,cf,cm;
LL m,pre[N],nex[N],A;
struct node
{
int a,id;
}po[N];
int cmp(node x,node y)
{
return x.a<y.a;
}
int cmp1(node x,node y)
{
return x.id<y.id;
}
int check(LL y,LL x,int fr)
{
int l=,r=fr;
while(l<=r)
{
int mid=(l+r)>>;
if(po[mid].a<=x)l=mid+;
else r=mid-;
}
if(y>=x*(l-)-pre[l-])return ;
return ;
} int fipos,fnum;
int tpos,tnum;
LL solve(int x)
{
int num=n+-x;
if(m>=num*A-nex[x])
{
LL temp=m-num*A+nex[x];
LL l=po[].a,r=A;
while(l<=r)
{
LL mid=(l+r)>>;
if(check(temp,mid,x-))l=mid+;
else r=mid-;
}
tpos=(int)(l-),tnum=num;
return (l-)*cm+num*cf;
}
return ;
}
int main()
{
read(n);read(A);read(cf);read(cm);read(m);
Riep(n)read(po[i].a),po[i].id=i;
sort(po+,po+n+,cmp);
pre[]=;nex[n+]=;
for(int i=;i<=n;i++)pre[i]=pre[i-]+po[i].a;
for(int i=n;i>;i--)nex[i]=nex[i+]+po[i].a;
int pos=;
LL ans=;
for(int i=n+;i>;i--)
{
LL d=solve(i);
if(d>ans)
{
ans=d;
pos=i;
fipos=tpos;
fnum=tnum;
}
}
cout<<ans<<"\n";
for(int i=n;i>n-fnum;i--)
{
po[i].a=(int)A;
}
for(int i=;i<=n;i++)
{
if(po[i].a<fipos)po[i].a=fipos;
}
sort(po+,po+n+,cmp1);
Riep(n)printf("%d ",po[i].a);
return ;
}

codeforces 613B B. Skills(枚举+二分+贪心)的更多相关文章

  1. CodeForces 377B---Preparing for the Contest(二分+贪心)

    C - Preparing for the Contest Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d ...

  2. Codeforces C Match Points(二分贪心)

    题目描述: Match Points time limit per test 2 seconds memory limit per test 256 mega bytes input standard ...

  3. codeforces 1251D Salary Changing (二分+贪心)

    (点击此处查看原题) 题意分析 一共有s元钱,要用这些钱给n个人发工资,发给每个人的工资si有最少和最多限制 si ∈[li,ri],在发给n个人的总工资小于s的情况下,要求发给n个人中的工资的中位数 ...

  4. 【CodeForces 613B】Skills

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

  5. Codeforces Round #262 (Div. 2) 二分+贪心

    题目链接 B Little Dima and Equation 题意:给a, b,c 给一个公式,s(x)为x的各个位上的数字和,求有多少个x. 分析:直接枚举x肯定超时,会发现s(x)范围只有只有1 ...

  6. Codeforces 497B Tennis Game( 枚举+ 二分)

    B. Tennis Game time limit per test 2 seconds memory limit per test 256 megabytes input standard inpu ...

  7. CodeForces 551C - GukiZ hates Boxes - [二分+贪心]

    题目链接:http://codeforces.com/problemset/problem/551/C time limit per test 2 seconds memory limit per t ...

  8. Codeforces Gym 100231B Intervals 线段树+二分+贪心

    Intervals 题目连接: http://codeforces.com/gym/100231/attachments Description 给你n个区间,告诉你每个区间内都有ci个数 然后你需要 ...

  9. Codeforces C. Maximum Value(枚举二分)

    题目描述: Maximum Value time limit per test 1 second memory limit per test 256 megabytes input standard ...

随机推荐

  1. Objc基础学习记录3

    在学习Objective-c中, 数组 1.NSArray, 这是一个不可变的数组,不能修改和删除其中的对象,可以存储任意objective的对象指针. 不能存储int,char类型的,,需要转换为需 ...

  2. Ajax.ActionLink与Ajax.BeginForm使用场所的思考

    Ajax.ActionLink使用在提交参数明确的情况下,如: Ajax.ActionLink("加入购物车", "AddToCart", "Cart ...

  3. MFC 构建、消亡 顺序 (二)--多文档 (MDI)

    MFC 构建.消亡 顺序 (二)--多文档 (MDI) by:http://www.cnblogs.com/vranger/ (一)MDI 生成顺序 (二)打开文档-“Open” (三)新建文档-“N ...

  4. Git版本管理:Windows下Git配置与使用指南

    简要介绍:Git是一个开源的分布式版本控制系统,用以有效.高速的处理从很小到非常大的项目版本管理. 一.安装 软件:msysGit-fullinstall-1.8.1.2 打开之后设置安装路径,默认为 ...

  5. 【ps】gif动态图白边问题

    (从死了一次又一次终于挂掉的百度空间中抢救出来的,发表日期 2014-08-13) 在制作gif动态图的时候发现有白边问题 网上说可以设成索引,但是这样一整连动画帧都一块丢掉了. 最终解决办法: 将要 ...

  6. 把java文件打包成.jar (jar命令详解)

    把java文件打包成.jar (jar命令详解) 先打开命令提示符(win2000或在运行框里执行cmd命令,win98为DOS提示符),输入jar Chelp,然后回车(如果你盘上已经有了jdk1. ...

  7. Java面试试题

    第一,谈谈final, finally, finalize的区别.最常被问到. 第二,Anonymous Inner Class (匿名内部类) 是否可以extends(继承)其它类,是否可以impl ...

  8. linux下mysql开启慢查询

    mysql中最影响速度的就是那些查询很慢的语句.这些慢的语句,可能是写的不够合理或者是大数据下多表的联合查询等等.所以我们要找出这些语句,分析原因,加以优化. 1.方法1:用命令开启慢查询 1).查看 ...

  9. [Unity3D]Unity3D游戏开发之在3D场景中选择物体并显示轮廓效果

    大家好,我是秦元培,欢迎大家关注我的博客,我的博客地址是blog.csdn.net/qinyuanpei. 在<仙剑奇侠传>.<古剑奇谭>等游戏中,常常须要玩家在一个3D场景中 ...

  10. SGU 538. Emoticons 水题

    538. Emoticons 题目连接: http://acm.sgu.ru/problem.php?contest=0&problem=538 Description A berland n ...