Codeforces Round #339 (Div. 1) B. Skills 暴力 二分
B. Skills
题目连接:
http://www.codeforces.com/contest/613/problem/B
Description
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.
Input
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.
Output
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.
Sample Input
3 5 10 1 5
1 3 1
Sample Output
12
2 5 2
Hint
题意
你有n个技能,每个技能最高A级,你还有m个技能点没加
然后你的实力等于最低的技能等级*cm+等级加满的技能数量*cf
现在问你怎么加点,可以使得你的实力最大
题解:
首先贪心,我加满的技能,肯定是从高往低加
我要提高最低的技能,肯定从低到高加
那么我就枚举我加满的技能数量,然后二分我究竟能够加多少个最低的技能。
代码
#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e5+7;
int n;
long long A,cf,cm,m;
pair<long long ,int> a[maxn];
long long b[maxn],c[maxn];
bool cmp(pair<long long ,int> aa,pair<long long ,int> bb)
{
return aa.second<bb.second;
}
int main()
{
scanf("%d%lld%lld%lld%lld",&n,&A,&cf,&cm,&m);
for(int i=1;i<=n;i++)
scanf("%lld",&a[i].first),a[i].second=i;
sort(a+1,a+1+n);
for(int i=1;i<=n;i++)
{
b[i]=b[i-1]+a[i].first;
c[i]=a[i].first*i-b[i];
}
long long ans = 0,ans1 = 0,ans2 = 0;
for(int i=0;i<n;i++)
{
if(m<0)break;
int pos = upper_bound(c,c+1+(n-i),m)-c-1;
long long q = (m-c[pos])/pos+a[pos].first;
q = min(q,A);
long long tmp = q*cm+i*cf;
if(tmp>ans)
{
ans = tmp;
ans1 = q,ans2 = i;
}
m = m - (A - a[n-i].first);
}
if(m>=0)
ans = A*cm+n*cf;
printf("%lld\n",ans);
for(int i=1;i<=n;i++)
{
if(n-i<ans2)
a[i].first = A;
else if(a[i].first<=ans1)
a[i].first = ans1;
}
sort(a+1,a+1+n,cmp);
for(int i=1;i<=n;i++)
printf("%lld ",a[i].first);
}
Codeforces Round #339 (Div. 1) B. Skills 暴力 二分的更多相关文章
- Codeforces Round #339 (Div.2)
A. Link/Cut Tree time limit per test 2 seconds memory limit per test 256 megabytes input standard in ...
- Codeforces Round #307 (Div. 2) B. ZgukistringZ 暴力
B. ZgukistringZ Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/551/probl ...
- Codeforces Round #328 (Div. 2) A. PawnChess 暴力
A. PawnChess Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/592/problem/ ...
- Codeforces Round #404 (Div. 2)(A.水,暴力,B,排序,贪心)
A. Anton and Polyhedrons time limit per test:2 seconds memory limit per test:256 megabytes input:sta ...
- Codeforces Round #369 (Div. 2) A B 暴力 模拟
A. Bus to Udayland time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- Codeforces Round #339 (Div. 1) A. Peter and Snow Blower 计算几何
A. Peter and Snow Blower 题目连接: http://www.codeforces.com/contest/613/problem/A Description Peter got ...
- Codeforces Round #339 (Div. 2) B. Gena's Code 水题
B. Gena's Code 题目连接: http://www.codeforces.com/contest/614/problem/B Description It's the year 4527 ...
- Codeforces Round #339 (Div. 2) A. Link/Cut Tree 水题
A. Link/Cut Tree 题目连接: http://www.codeforces.com/contest/614/problem/A Description Programmer Rostis ...
- Codeforces Round #188 (Div. 1) B. Ants 暴力
B. Ants Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/317/problem/B Des ...
随机推荐
- Msfvenom学习总结-MSF反弹webshell
1. –p (- -payload-options) 添加载荷payload. 载荷这个东西比较多,这个软件就是根据对应的载荷payload生成对应平台下的后门,所以只有选对payload,再填 ...
- DIV+CSS左右列高度自适应问题
其实解决DIV+CSS左右两列高度自适应的方法就是要注意两点:一是在最外层加上overflow:hidden,然后在左边列加上margin-bottom:-9999px;padding-bottom: ...
- [device tree] interrupt
Specifying interrupt information for devices ============================================ 1) Interru ...
- 【bzoj3682】Phorni
后缀平衡树裸题. 后缀平衡树呢,实际上是一个很naive的东西.就是用平衡树维护后缀数组. 这样的话就可以支持在最前端插入一个字符(相当于插入新的后缀) 每次比较节点的tag是O(1)的,所以可以快速 ...
- HDU 6109 数据分割 并查集,SET
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6109 题意:中文题面 解法:每次都贪心地尝试将尽量多的条件放进当前这组,遇到第一个与已有条件冲突时,就 ...
- C#调用Excel报 error CS1969: 找不到编译动态表达式所需的一个或多个类型。是否缺少引用?
转自[http://blog.csdn.net/bodybo/article/details/43191319] 程序需要读取Exel文件,有如下代码段 object oMissing = Syste ...
- CSS3 icon font
大家都知道现在各个浏览器都支持CSS3的自定义字体(@font-face),包括IE6都支持,只是各自对字体文件格式的支持不太一样.那么对于网站中用到的各种icon,我们就可以尝试使用font来实现, ...
- Leetcode 之Binary Tree Postorder Traversal(44)
后序遍历,比先序和中序都要复杂.访问一个结点前,需要先判断其右孩子是否被访问过.如果是,则可以访问该结点:否则,需要先处理右子树. vector<int> postorderTravers ...
- leetcode 之Gas Station(11)
这题的思路很巧妙,用两个变量,一个变量衡量当前指针是否有效,一个衡量整个数组是否有解,需要好好体会. int gasStation(vector<int> &gas, vector ...
- java.util.ConcurrentModification并发修改异常
在运行下面这段代码时出现了并发修改异常java.util.ConcurrentModification: public static void main(String[] args) { List l ...