CodeForces 614D Skills
排序+枚举+二分
最大的那些变成A,小的那部分提高最小值
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std; const int maxn=+;
int n;
long long A,cf,cm,m;
struct X
{
long long a;
long long ans;
int id;
} s[maxn];
long long sum[maxn]; bool cmp1(const X&a,const X&b)
{
return a.a<b.a;
} bool cmp2(const X&a,const X&b)
{
return a.id<b.id;
} int main()
{
scanf("%d%lld%lld%lld%lld",&n,&A,&cf,&cm,&m);
for(int i=; i<=n; i++)
{
scanf("%lld",&s[i].a);
s[i].id=i;
s[i].ans=s[i].a;
}
sort(s+,s++n,cmp1);
memset(sum,,sizeof sum);
for(int i=; i<=n; i++) sum[i]=sum[i-]+s[i].a;
int ansPos1=,ansPos2=;
long long Max=-;
long long ave=;
for(int i=; i<=n; i++) //最后i个都变成A
{
long long cost=A*i-(sum[n]-sum[n-i]);//最后i个都变成A需要的费用
if(cost>m) break;// 如果费用超过了m,则结束 cost=m-cost;//剩余的费用
int left=,right=n-i;//二分查找的范围
int pos=;
while(left<=right)
{
int mid=(left+right)/;
if(mid*s[mid].a-sum[mid]<=cost)
{
pos=mid;
left=mid+;
}
else right=mid-;
}
long long q;
if(pos!=) q=min(A,(cost-pos*s[pos].a+sum[pos])/pos+s[pos].a);
else q=A;
if(q*cm+i*cf>Max)
{
Max=q*cm+i*cf;
ansPos1=pos;
ansPos2=i;
ave=q;
}
} for(int i=n;i>=n-ansPos2+;i--) s[i].ans=A;
for(int i=;i<=ansPos1;i++) s[i].ans=ave; printf("%lld\n",Max);
sort(s+,s+n+,cmp2);
for(int i=;i<=n;i++)
{
printf("%lld",s[i].ans);
if(i<n) printf(" ");
else printf("\n");
}
return ;
}
CodeForces 614D Skills的更多相关文章
- [CodeForces - 614D] D - Skills
D - Skills Lesha plays the recently published new version of the legendary game hacknet. In this ver ...
- Skills CodeForces - 614D (贪心)
链接 大意: $n$门课, 第$i$门分数$a_i$, 可以增加共$m$分, 求$cnt_{mx}*cf+mi*cm$的最大值 $cnt_{mx}$为满分的科目数, $mi$为最低分, $cf$, $ ...
- 「日常训练」Skills(Codeforce Round #339 Div.2 D)
题意(CodeForces 614D) 每个人有\(n(n\le 10^5)\)个技能,技能等级都在\([0,10^9]\)的范围,每个技能有一个当前等级,所有技能的最高等级都为A.一个人的力量被记做 ...
- 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 ...
- Codeforces Round #339 (Div. 1) B. Skills 暴力 二分
B. Skills 题目连接: http://www.codeforces.com/contest/613/problem/B Description Lesha plays the recently ...
- codeforces 581C. Developing Skills 解题报告
题目链接:http://codeforces.com/problemset/problem/581/C 题目意思:给出 n 个数:a1, a2, ..., an (0 ≤ ai ≤ 100).给出值 ...
- codeforces 613B B. Skills(枚举+二分+贪心)
题目链接: B. Skills time limit per test 2 seconds memory limit per test 256 megabytes input standard inp ...
- 【CodeForces 613B】Skills
题 题意 给你n个数,可以花费1使得数字+1,最大加到A,最多花费m.最后,n个数里的最小值为min,为A的有k个,给你cm和cf,求force=min*cm+k*cf 的最大值,和n个数操作后的结果 ...
- Skills CodeForces - 613B (双指针)
大意: $n$门课, 第$i$门分数$a_i$, 可以增加共$m$分, 求$cnt_{mx}*cf+mi*cm$的最大值 $cnt_{mx}$为满分的科目数, $mi$为最低分, $cf$, $cm$ ...
随机推荐
- wamp本地能访问,但局域网不能访问的解决办法
Apache的配置文件.
- 关于table参数的一些问题
1.关于单元格合并 写在td标签上,如: <td rowspan="3"></td> 跨行合并:rowspan 跨列合并:colspan 2.关于多行输入框 ...
- Bitmap和Drawable浅谈
一.概念区别 Bitmap - 称作位图,一般位图的文件格式后缀为bmp,当然编码器也有很多如RGB565.RGB8888.作为一种逐像素的显示对象执行效率高,但是缺点也很明显存储效率低.我们理解为一 ...
- DataGirdView 编辑项时的验证
dgvConfig.DataSource = CreateTable(); dgvConfig.Columns["编号"].ReadOnly = true; //只读 dgvCon ...
- Ant 参考
http://ant.apache.org/manual/Tasks/exec.html Exec Description Executes a system command. When the os ...
- jquery 限制字数 显示输入字数 插件
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- SuperSocket+unity 网络笔记
学习SuperSocket 必须要注意的 代码是 static void Main(string[] args) { WebSocketServer appServer = new WebSocket ...
- AI 人工智能 探索 (一)
碰撞检测 //逗留碰撞 void OnTriggerStay (Collider other) { if (other.transform.name == name) { //检测距离 //根据距离 ...
- 线程带参数的Udp接收
//work wk = new work(ReadUdpDate); ParameterizedThreadStart parmThre = new ParameterizedThreadStart( ...
- HDU 4612 Warm up(双连通分量缩点+求树的直径)
思路:强连通分量缩点,建立一颗新的树,然后求树的最长直径,然后加上一条边能够去掉的桥数,就是直径的长度. 树的直径长度的求法:两次bfs可以求,第一次随便找一个点u,然后进行bfs搜到的最后一个点v, ...