codeforces 613B B. Skills(枚举+二分+贪心)
题目链接:
2 seconds
256 megabytes
standard input
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.
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.
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.
3 5 10 1 5
1 3 1
12
2 5 2
3 5 10 1 339
1 3 1
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(枚举+二分+贪心)的更多相关文章
- CodeForces 377B---Preparing for the Contest(二分+贪心)
C - Preparing for the Contest Time Limit:2000MS Memory Limit:262144KB 64bit IO Format:%I64d ...
- Codeforces C Match Points(二分贪心)
题目描述: Match Points time limit per test 2 seconds memory limit per test 256 mega bytes input standard ...
- codeforces 1251D Salary Changing (二分+贪心)
(点击此处查看原题) 题意分析 一共有s元钱,要用这些钱给n个人发工资,发给每个人的工资si有最少和最多限制 si ∈[li,ri],在发给n个人的总工资小于s的情况下,要求发给n个人中的工资的中位数 ...
- 【CodeForces 613B】Skills
题 题意 给你n个数,可以花费1使得数字+1,最大加到A,最多花费m.最后,n个数里的最小值为min,为A的有k个,给你cm和cf,求force=min*cm+k*cf 的最大值,和n个数操作后的结果 ...
- Codeforces Round #262 (Div. 2) 二分+贪心
题目链接 B Little Dima and Equation 题意:给a, b,c 给一个公式,s(x)为x的各个位上的数字和,求有多少个x. 分析:直接枚举x肯定超时,会发现s(x)范围只有只有1 ...
- Codeforces 497B Tennis Game( 枚举+ 二分)
B. Tennis Game time limit per test 2 seconds memory limit per test 256 megabytes input standard inpu ...
- CodeForces 551C - GukiZ hates Boxes - [二分+贪心]
题目链接:http://codeforces.com/problemset/problem/551/C time limit per test 2 seconds memory limit per t ...
- Codeforces Gym 100231B Intervals 线段树+二分+贪心
Intervals 题目连接: http://codeforces.com/gym/100231/attachments Description 给你n个区间,告诉你每个区间内都有ci个数 然后你需要 ...
- Codeforces C. Maximum Value(枚举二分)
题目描述: Maximum Value time limit per test 1 second memory limit per test 256 megabytes input standard ...
随机推荐
- js全局变量
在做东钿微信公众号 ,首页有房产评估和产调,有个checkbox ,点击则选中使用积分,取消选中则不使用积分,html结构和css样式都一样,唯一不一样的就是数据不一样,于是我就分开来写,没有写同一个 ...
- android 自定义控件(初篇)
android 自定义控件 在写UI当中很多时候会用到自定义的控件,其实自定义控件就像是定义一个类进行调用就OK了.有些相关的感念可以查看API 下面就用个简单的例子来说明自定义控件: public ...
- STL 速解
STL(Standard Template Library)是C++的标准模版库. STL概述 STL的一个重要概念是数据结构和算法的分离,这使得STL变得十分通用.例如:由于STL的sort()函数 ...
- 如何选择PDA的操作系统? Android OR WINCE?
PDA(Personal Digital Assistant),又称为掌上电脑,可以帮助我们完成在移动中工作,学习,娱乐等.按使用来分类,分为工业级PDA和消费品PDA.当我们需要购买PDA的时候, ...
- 理解Web标准(网站标准)
我觉得一名Web前端应该好好理解Web标准到底是什么,为什么要在我们的实际实践中遵循Web标准. 什么是Web标准.百度百科的解释是: WEB标准不是某一个标准,而是一系列标准的集合.网页主要由三部分 ...
- li中包含span,在IE6、IE7下会有3pxbug
如果给每个li里面加个span标签的话,在IE6,IE7下看,li与li之间的距离就会多了3px. 解决方法:在li中加vertical-align:middle; <div class=&qu ...
- hotfix分析
使用System Update Readiness Tool for Windows Server 2008 R2 x64 可以分析hotfix是否有安装失败的情况 示例:http://blogs.t ...
- maven的学习系列(四)—创建maven项目注意事项
文件夹: <1> 中央工厂的位置 <2>mvn archetype:generate <3>Eclipse配置maven <4>在Eclipse中创建简 ...
- LFS7.4编译笔记(1)
由于第一次编译,花了不少时间,也不知道能不能成功,所以就没有记笔记,现在重新编译一次,这次不装U盘而是装到我的移动硬盘上面.步骤差不多,因为我感觉硬盘的速度会比U盘快. 至于LFS的优点,我就不多说了 ...
- Android图片圆角效果
一般来说图片加圆角可以使用 Java 的方式来进行, 对图片略加处理即可, 但也可以使用纯XML+Nice-Patch图片来进行, 这样的速度会更快. 如果背景是纯色的情况下建议使用此方法. 原理则是 ...