D - Skills

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

Example

Input
3 5 10 1 51 3 1
Output
122 5 2 
Input
3 5 10 1 3391 3 1
Output
355 5 5 

Note

In the first test the optimal strategy is to increase the second skill to its maximum, and increase the two others by 1.

In the second test one should increase all skills to maximum.

题目的意思是,有几个技能,每个技能有一个初始等级,所有技能有一个共同的最大等级限度.现在你有几次升级的机会,要求升级之后,某个值最大化.

其中,这个值的计算方式是,满级的个数*常数1+等级最低值*常数2.

那么,我们可以枚举满级的个数,然后二分求解最小值,并且尽可能使其最大化.

假设我们现在枚举了有i个满级的,那么,要计算出剩下的钱还有多少,然后进行二分答案,枚举low,表示想让所有的等级都不小于low.

那么原来等级小于low的肯定要升级,花钱.如果钱够花就可以.

但是又有一个问题,在枚举+二分时,已经是nlogn的复杂度了,再套个n肯定TLE.而我们有需要知道,到底有几个等级小于low,以及总共少了多少.那么,对于这个问题,我们可以通过二分查找来实现.

所以,最后的复杂度是nlogn^2(注意,在更新答案的时候不要o(n)更新!!!可以取几个关键的值,最后再更新,还要注意数据类型).

 #include<cstdio>
 #include<cstring>
 #include<algorithm>
 using namespace std;
 ;
 int n,A,out[maxn];
 struct data{
     int x,i;
     bool operator < (const data &u) const {return x<u.x;}
 }cur[maxn];
 long long cf,cm,m;
 long long s[maxn],ans;
 int f1,f2,f3;
 inline long long read(){
     ; char ch=getchar();
     ') ch=getchar();
     +ch-',ch=getchar();
     return x;
 }
 int bis(int low){
     ,r=n,md;
     ;
     if (low>cur[r].x) return r;
     while (l<=r){
         md=(l+r)>>;
         ].x<low&&low<=cur[md].x) ;
         ].x) r=md-; ;
     }
 }
 bool jug(int low,long long money,int num){
     int x=min(n-num,bis(low));
     long long s1=s[x],s2=(long long)low*x;
     if (s1+money>=s2){
         ;
         ans=cf*num+cm*low; f1=low; f2=x; f3=num;
         ;
     }
     ;
 }
 int main(){
     n=(]=;
     ; i<=n; i++) cur[i].x=(].x=A;
     sort(cur+,cur++n);
     memset(,sizeof out);
     ans=cm*cur[].x;
     ; i<=n; i++) if (cur[i].x==A) ans+=cf;
     ; i<=n; i++) out[cur[i].i]=cur[i].x;
     ; i<=n; i++) s[i]=s[i-]+cur[i].x;
     ;
     ; i<=n; i++){
         ].x) sum+=A-cur[n-i+].x;
         if (sum>m) break;
         ].x,R=A,mid;
         while (L<=R){
             mid=(L+R)>>;
             ; ;
         }
     }
     memset(,sizeof out);
     ; i<=f2; i++) out[cur[i].i]=f1;
     ; i<=n-f3; i++) out[cur[i].i]=cur[i].x;
     ; i<=n; i++) out[cur[i].i]=A;
     printf("%lld\n",ans);
     ; i<=n; i++) printf("%d ",out[i]);
     ;
 }

[CodeForces - 614D] D - Skills的更多相关文章

  1. CodeForces 614D Skills

    排序+枚举+二分 最大的那些变成A,小的那部分提高最小值 #include<cstdio> #include<cstring> #include<cmath> #i ...

  2. Skills CodeForces - 614D (贪心)

    链接 大意: $n$门课, 第$i$门分数$a_i$, 可以增加共$m$分, 求$cnt_{mx}*cf+mi*cm$的最大值 $cnt_{mx}$为满分的科目数, $mi$为最低分, $cf$, $ ...

  3. codeforces 581C. Developing Skills 解题报告

    题目链接:http://codeforces.com/problemset/problem/581/C 题目意思:给出 n 个数:a1, a2, ..., an (0 ≤ ai ≤ 100).给出值 ...

  4. codeforces 613B B. Skills(枚举+二分+贪心)

    题目链接: B. Skills time limit per test 2 seconds memory limit per test 256 megabytes input standard inp ...

  5. 【CodeForces 613B】Skills

    题 题意 给你n个数,可以花费1使得数字+1,最大加到A,最多花费m.最后,n个数里的最小值为min,为A的有k个,给你cm和cf,求force=min*cm+k*cf 的最大值,和n个数操作后的结果 ...

  6. 「日常训练」Skills(Codeforce Round #339 Div.2 D)

    题意(CodeForces 614D) 每个人有\(n(n\le 10^5)\)个技能,技能等级都在\([0,10^9]\)的范围,每个技能有一个当前等级,所有技能的最高等级都为A.一个人的力量被记做 ...

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

  8. Codeforces Round #339 (Div. 1) B. Skills 暴力 二分

    B. Skills 题目连接: http://www.codeforces.com/contest/613/problem/B Description Lesha plays the recently ...

  9. Skills CodeForces - 613B (双指针)

    大意: $n$门课, 第$i$门分数$a_i$, 可以增加共$m$分, 求$cnt_{mx}*cf+mi*cm$的最大值 $cnt_{mx}$为满分的科目数, $mi$为最低分, $cf$, $cm$ ...

随机推荐

  1. js捕获错误

    文: http://www.jb51.net/article/78764.htm 用window.onerror捕获并上报Js错误的方法 前两天有个2048游戏的用户反馈说,打开游戏后不能玩儿,只有一 ...

  2. [UVA-11100] The Trip

    题目大意 大箱子能装小箱子,求在满足最少箱子的情况下,最小化每个箱子中最大的箱子个数. 解析 想到二分枚举箱子数,然后贪心的选择放进箱子的位置. 最优策略一定是将最大的 \(m\) 个先找出来,然后把 ...

  3. 51nod 1052 最大M子段和

    http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1052 题意: 思路:设$dp[i][j]$表示前j个数构成i个字段时的最 ...

  4. Data Structure 基本概念

    数据(data) 描述客观事物的数值 数据项(data item) 具有原子性,不可分割的最小单位 数据元素(data element)集合的个体,通常由很多数据组成 数据对象(data object ...

  5. char,String,int类型互转

    1.ascci码对应转换 字符,对应的ascii(其实是UTF-16)码:     char c='a'; int k=(int) c;    结果k=97 数字,对应的字符:     int k=9 ...

  6. python3使用pymysql模块,连接mysql数据库,实现新增、查询和更新操作

    1.环境数据准备: python3环境.pymysql模块 mysql数据库:本次代码中用到的数据库为本地的testdb数据库,user表(表字段比较简单,只有主键id,手机号mobile,密码pas ...

  7. cookie的常用操作

    cookie介绍: 1. cookie的简单介绍就是把用户的登录信息缓存在本机的浏览器中,且最大容量为4KB, 2. 这种存储是不安全的,通常一般会进行加密处理,但是依旧不能做到安全,所以一般要优先考 ...

  8. 主动触发事件 自定义事件 trigger 及其用法

    1. 触发自定义事件方式 js.jq 2. jq 触发 2.1 默认支持的事件 $('#h').on('click',function(){ $(this).append('<p>p< ...

  9. 新建ng工程

    有问题多看官网文档https://www.angular.cn/guide/quickstart 1 在远程仓库建立 1个完全空的仓库,不要建立readme.MD  ng cli创建时会创建readm ...

  10. x1c 2018 莫名卡顿

    win10不知更新了什么,x1c非常卡一跳一跳的,很多年没见过了-_-!! CPU占用低,但是特别之卡…… (也许是Lenovo的更新,反正是在window update里一起的 —————————— ...