题解:CF613B Skills
这有蓝?
显然的事情是升满是从大往小考虑,提高最低的等级是从小往大考虑,两者互不影响,所以先把所有技能按照等级排序,于是考虑枚举
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int maxn = 1e5+114;
const int inf = 1e18+114;
int n,A,m,a[maxn];
pair<int,int> b[maxn];
int p[maxn];
int cm,cf;
int pre[maxn];
bool check(int x,int w,int cst){
//[1,x] 升到 w 花费是否不超过 cst
return w*x-pre[x]<=cst;
}
int cha,chb;
int solve(int x){
if(A*x-(pre[n]-pre[n-x])>m) return -inf;
int cst=m-(A*x-(pre[n]-pre[n-x]));
int l=0,r=A+1;
while(l+1<r){
int mid=(l+r)>>1;
int L=1,R=n-x+1;
while(L+1<R){
int Mid=(L+R)>>1;
if(a[Mid]<=mid) L=Mid;
else R=Mid;
}
if(check(L,mid,cst)) l=mid;
else r=mid;
}
if(x==n) l=A;
cha=x,chb=l;
return x*cf+l*cm;
}
signed main(){
ios::sync_with_stdio(0);
cin.tie(0),cout.tie(0);
cin>>n>>A>>cf>>cm>>m;
for(int i=1;i<=n;i++) cin>>a[i],b[i].first=a[i],b[i].second=i;
sort(a+1,a+n+1);
sort(b+1,b+n+1);
for(int i=1;i<=n;i++) p[b[i].second]=i;
for(int i=1;i<=n;i++) pre[i]=pre[i-1]+a[i];
int ans=0,P=1;
for(int i=0;i<=n;i++){
int res=solve(i);
if(res>=ans){
ans=res;
P=i;
}
}
cout<<ans<<'\n';
solve(P);
for(int i=1;i<=n;i++){
if(n-p[i]+1<=cha) cout<<A<<' ';
else cout<<max(chb,a[p[i]])<<' ';
}
return 0;
}