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$ ...
随机推荐
- server服务器信息页面添加步骤
1. 在数据库更新链接 /portal/server/getServerList 2. 写实体类 Server.java 3. 写Server.hbm.xml <?xml version=&qu ...
- PHP详解$_SEVER常用变量
$_SERVER['HTTP_ACCEPT_LANGUAGE']//浏览器语言 $_SERVER['HTTP_ACCEPT'] //当前请求的Accept头部的内容,例如text/html,appli ...
- 最大独立集 HDU 1068
题目大意:有n个人,两个人之间有相互的关系,问最大的关系数目. 思路:n-(最大匹配数/2).因为这里给出的是n个人之间的两两关系 //看看会不会爆int!数组会不会少了一维! //取物问题一定要小心 ...
- [转]c++ new带括号和不带括号
ref:http://m.blog.csdn.net/blog/u012745772/42420443 在new对象的时候有加上(),有不加(),不知道这个到底是什么区别?比如:CBase *base ...
- document.querySelectorAll遍历(forEach小解)
document.querySelectorAll兼容性良好,在之前的项目中就其遍历方式出了错误,先做个小结: 1.for循环 传统遍历方法 for(var i= 0; i< document. ...
- DB INIT IN WINDOWS (FOR 12C)
Uat oracleDB-Uat 192.168.63.121 Windows server 2012 R2 2核12G,硬盘160G 内置用户是oaadm ...
- DISUBSTR - Distinct Substrings
DISUBSTR - Distinct Substrings no tags Given a string, we need to find the total number of its dist ...
- GCD应用场景
1.计算文件大小放在子线程中中计算,计算完了,回到主线程更新UI
- JDBC 事务隔离级别
JDBC 事务隔离级别 先解释一下:a:脏读取:一个事务读取了另外一个并行事务未提交的数据b:不可重复读取:一个事务再次读取之前的数据时得到的数据不一致,被另外一个事务修改c:虚读:一个事务重 ...
- ibatis 自动生成map,bean,dao
1.下载 AbatorForEclipse1.1.0 地址:http://download.csdn.net/detail/fym548/9426877 点击Archive按钮选择下载的,然后重启My ...