[CodeForces - 614D] D - Skills

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]);
     ;
 }
上一篇:iproute2学习笔记


下一篇:【代码笔记】Web-ionic-Range