题目链接:

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. 集成Jenkins Notifier for Chrome到Jenkins CI

    Jenkins也算是现在最流行的CI工具了,我们team也使用它来做持续化集成的工作.最近需要增加弹出式窗口来提醒相关人员job的状态,故选择Jenkins Notifier for Chrome这个 ...

  2. JavaScript 跨域:谈谈跨域之 JSONP

    在 Web 开发中,后台开发人员应该会通常遇到这个问题:跨域,而使用 JSONP 就是其中解决办法之一,当然,还有其它解决方法,比如:window.name.window.postMessage.CO ...

  3. pad 横屏 cell不正常显示

    在iOS9中,适配iPad横屏的时候,我发现cell不能正常显示,其标题和线都不是从左边头部开始,而是在中间,accessoryType的图标也不再右边尾部,效果如下图 但是在iPhone中是正常的, ...

  4. Java常见排序算法之折半插入排序

    在学习算法的过程中,我们难免会接触很多和排序相关的算法.总而言之,对于任何编程人员来说,基本的排序算法是必须要掌握的. 从今天开始,我们将要进行基本的排序算法的讲解.Are you ready?Let ...

  5. 【M25】将构造方法和非成员方法虚化

    1.所谓虚化,就是根据引用或者指针的真实类型,决定调用哪个方法. 2.构造方法虚化,就是根据引用(或者指针)的真实类型,构造出一个对象,如果指针的真实类型是Base,返回Base*:如果指针的真实类型 ...

  6. UVA 12898 And Or 数学暴力

    And Or Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/view.actio ...

  7. Redis缓存服务搭建及实现数据读写

    发现博客园中好多大牛在介绍自己的开源项目是很少用到缓存,比如Memcached.Redis.mongodb等,今天得空抽时间把Redis缓存研究了一下,写下来总结一下,跟大家一起分享 一下.由于小弟水 ...

  8. HDU 1504 Disk Tree

    转载请注明出处:http://blog.csdn.net/a1dark 分析:查了一下这题.发现网上没有什么关于这道题的解题报告.其实题目意思挺好懂的.就是给你一些文件的目录结构.然后让你把它们组合在 ...

  9. iOS开发——多线程OC篇&(十一)多线程NSOperation高级用法

    自定义NSOperation 一.实现一个简单的tableView显示效果 实现效果展示: 代码示例(使用以前在主控制器中进行业务处理的方式) 1.新建一个项目,让控制器继承自UITableViewC ...

  10. oracle视图总结

    视图简介: 视图是基于一个表或多个表或视图的逻辑表,本身不包含数据,通过它可以对表里面的数据进行查询和修改.视图基于的表称为基表.视图是存储在数据字典里的一条select语句. 通过创建视图可以提取数 ...