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$ ...
随机推荐
- PHP编码相关函数试题
1.检查字符串在指定的编码里是否有效的函数是什么? 2.获取字符编码的函数是什么? 3.解析 GET/POST/COOKIE 数据并设置全局变量的函数是什么? 4.大小写不敏感地查找字符串在另一个字符 ...
- QQ 自动接收远程连接之关闭了远程桌面
之前使用都好好的,后来就不知道怎么了突然就不行了,在另外一个远程桌面软件(向日葵)失效后,木有办法,查查查,终于查出来了,是我本机的时间服务停止了,导致我本机的时间和服务器时间不一致,所以连接不上.只 ...
- 转载 C语言中volatile关键字的作用
一.前言 1.编译器优化介绍: 由于内存访问速度远不及CPU处理速度,为提高机器整体性能,在硬件上引入硬件高速缓存Cache,加速对内存的访问.另外在现代CPU中指令的执行并不一定严格按照顺序执行,没 ...
- wl18xx wifi编译出现没有编译wlcore_sdio的情况
打开config.mk ........................................................................................ ...
- 将页面内容转为Excel下载
使用:method1(table); 说明:参数table为table元素的ID; var idTmr; function getExplorer() { var explorer = window. ...
- phpstudy 安装memcached服务和memcache扩展
memcached安装步骤: 首先,将下载好的memcahed解压到某个文件目录下,例如 C:\memcached 然后,在cmd里,输入"C:\memcached\memcached.ex ...
- HALF<水题>
题意: 找出n/d=0.5的所有数.输入:test,x(代表n的位数,1<=x<=4).并且n和d的每一个位数不能有重复,也不能是0. 输入: 1 1 输出: the form 1/2 = ...
- 栅栏cyclicbarrier
栅栏类似闭锁,但是它们是有区别的. 1.闭锁用来等待事件,而栅栏用于等待其他线程.什么意思呢?就是说闭锁用来等待的事件就是countDown事件,只有该countDown事件执行后所有之前在等待的线程 ...
- android 学习之RecyclerView
RecyclerView:ListView的升级版,它提供了更好的性能而且更容易使用.该控件是一个可以装载大量的视图集合,并且可以非常效率的进行回收和滚动.当你list中的元素经常动态改变时可以使用R ...
- android 定时器总结
1:handler实现定时器的功能 Handler handler=new Handler(); //立即执行Runnable对象 public final boolean post(Runnab ...