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$ ...
随机推荐
- angular、bootstrap初稿搭建
1.bootstrap3.0中,ie8不兼容响应式设计 @media,需要添加如下2个查件 <!-- html5.js for IE less than 9 --> <!-- ...
- dip2px
package com.itheima.zhbj.utils; import android.content.Context; public class DensityUtils { public s ...
- pci 相关资料
1.http://www.cnblogs.com/image-eye/archive/2012/02/15/2352699.html
- (UE4) 动态加载DLL
目前还没有实现,实在搞不懂为什么,大概代码如下: //------------------------------------------------------------------------- ...
- C#后台绑定ComboBox
C# using System; using System.Collections.Generic; using System.Linq; using System.Text; using Syste ...
- 【滚动数组】 dp poj 1036
题意:一群匪徒要进入一个酒店.酒店的门有k+1个状态,每个匪徒的参数是:进入时间,符合的状态,携带的钱. 酒店的门刚开始状态0,问最多这个酒店能得到的钱数. 思路: dp数组为DP[T][K]. 转移 ...
- ligerUI调用$.ligerDialog.open弹出窗口,关闭后无法获取焦点问题
1:调用父窗口某一个文件框,获取焦点, parent.window.document.getElementByIdx_x("roleName").focus(); 2:关闭父窗 ...
- OpenGL一些函数详解(二)
OpenGL ES顶点数据绘制技巧 在OpenGL中,绘制一个长方体,需要将每个顶点的坐标放在一个数组中.保存坐标时有一些技巧(由于字母下标不好表示,因此将下标表示为单引号,如A1将在后文中表示为A' ...
- UVALive 2324 Human Gene Functions(动态规划)
题意:求出将两个字符串改成一样长度所能形成最大的相似度. 思路:这个可以说是编辑距离的一个变形,编辑距离最终状态时要两个字符串完全一致,这个就是要求长度一样,而且这个只允许插入“—”这一个字符.模仿编 ...
- android ScrollView嵌套EditText
editext.setOnTouchListener(new OnTouchListener() { @Override publi ...