大意: $n$门课, 第$i$门分数$a_i$, 可以增加共$m$分, 求$cnt_{mx}*cf+mi*cm$的最大值 $cnt_{mx}$为满分的科目数, $mi$为最低分, $cf$, $cm$为给定系数
枚举满分的个数, 双指针求出最低分的最大值.
#include <iostream>
#include <sstream>
#include <algorithm>
#include <cstdio>
#include <math.h>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <string.h>
#include <bitset>
#define REP(i,a,n) for(int i=a;i<=n;++i)
#define PER(i,a,n) for(int i=n;i>=a;--i)
#define hr putchar(10)
#define pb push_back
#define lc (o<<1)
#define rc (lc|1)
#define mid ((l+r)>>1)
#define ls lc,l,mid
#define rs rc,mid+1,r
#define x first
#define y second
#define io std::ios::sync_with_stdio(false)
#define endl '\n'
#define DB(a) ({REP(__i,1,n) cout<<a[__i]<<' ';hr;})
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int P = 1e9+7, INF = 0x3f3f3f3f;
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
ll qpow(ll a,ll n) {ll r=1%P;for (a%=P;n;a=a*a%P,n>>=1)if(n&1)r=r*a%P;return r;}
ll inv(ll x){return x<=1?1:inv(P%x)*(P-P/x)%P;}
inline int rd() {int x=0;char p=getchar();while(p<'0'||p>'9')p=getchar();while(p>='0'&&p<='9')x=x*10+p-'0',p=getchar();return x;}
//head
#ifdef ONLINE_JUDGE
const int N = 1e6+10;
#else
const int N = 111;
#endif
int n, A, cf, cm, Ans[N];
ll sum[N], m;
pii a[N];
struct {int mi,now,cnt;} opt;
int main() {
scanf("%d%d%d%d%lld", &n, &A, &cf, &cm, &m);
REP(i,1,n) scanf("%d", &a[i].x),a[i].y=i;
sort(a+1,a+1+n);
REP(i,1,n) sum[i]=sum[i-1]+a[i].x;
ll ans = 0, res = m;
int now = 1;
while (now<n&&m+sum[now]>=(ll)now*a[now+1].x) ++now;
int mi = min((ll)A,a[now].x+(m+sum[now]-(ll)now*a[now].x)/now);
ans = (ll)mi*cm;
opt={mi,now,0};
REP(i,1,n) {
res = m-((ll)i*A-sum[n]+sum[n-i]);
if (res<0) break;
now = min(now, n-i);
while (now>1&&res+sum[now-1]<(ll)(now-1)*a[now].x) --now;
mi = min((ll)A,now?a[now].x+(res+sum[now]-(ll)now*a[now].x)/now:INF);
ll ret = (ll)i*cf+(ll)mi*cm;
if (ret>ans) ans = ret, opt = {mi,now,i};
}
printf("%lld\n", ans);
REP(i,1,opt.now) a[i].x=opt.mi;
REP(i,n-opt.cnt+1,n) a[i].x=A;
REP(i,1,n) Ans[a[i].y]=a[i].x;
REP(i,1,n) printf("%d ", Ans[i]);hr;
}