C - 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 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.
Examples
Input
3 5 10 1 5 1 3 1
Output
12 2 5 2
Input
3 5 10 1 339 1 3 1
Output
35 5 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.
题目大意:
给出了n个科目,每个科目有一个分数,有一个m代表可以用于增加的分数。然后又两个系数,最后的到的分数就是最低分数*cf+满分的科目数*cm;最高分数为A;
解题思路:
按照分数从小到大排序,枚举满分的科目数,然后二分枚举当前的可用分数对应的最低分是多少。
#include<iostream>
#include<cstdio>
#include<cstring>
#include<queue>
#include<set>
#include<algorithm>
#include<cmath>
#define rep(i,j,k) for(int i=j;i<=k;i++)
#define inf 0x3f3f3f3f
#define LL long long
#define sca(x) scanf("%d",&x)
using namespace std;
#define N 100005
struct node
{
LL v,p;
friend bool operator <(node x,node y)
{
return x.v<y.v;
}
}a[N];
LL b[N],sum[N];
int n;
bool cmp(node x,node y)
{
return x.p<y.p;
}
int main()
{
LL A,cf,cm,m;
cin>>n>>A>>cf>>cm>>m;
rep(i,1,n)scanf("%lld",&a[i].v),a[i].p=i;
sort(a+1,a+1+n);
sum[0]=0;
rep(i,1,n)b[i]=a[i].v;
rep(i,1,n)sum[i]=b[i]+sum[i-1];
a[n+1].v=A;
LL k1=0,k2=0;
LL num1=0,num2=0;
LL ans=-inf,val1,val2;
for(int i=n+1;i>=1;i--)
{
k1+=(A-a[i].v);
if(k1>m)continue;
k2=m-k1;
LL l=1,r=A;
while(l<=r)
{
LL mid=(l+r)>>1;
int cnt=lower_bound(b+1,b+1+i-1,mid)-b-1;
if(mid*cnt-sum[cnt]<=k2)l=mid+1;
else r=mid-1;
}
num1=n+1-i;
num2=r;
if(num2==A)
{
ans=n*cf+num2*cm;
val1=n;
val2=A;
}
else if(num1*cf+num2*cm>ans)
{
ans=num1*cf+num2*cm;
val1=num1;
val2=num2;
}
}
for(int i=n;i>=1,val1>=1;i--,val1--)a[i].v=A;
for(int i=1;i<=n;i++)if(a[i].v<val2)a[i].v=val2;
sort(a+1,a+1+n,cmp);
cout<<ans<<endl;
rep(i,1,n)printf("%lld%c",a[i].v,i==n?'\n':' ');
}