U528983
#include<bits/stdc++.h>
#define int long long
using namespace std;
int m,t,p,l,a[10005],pi,cnt=1,tot;
signed main(){
cin>>m>>t>>p>>l;
for(int i=1;i<=m;i++){
cin>>a[i];
pi+=a[i];
}
sort(a+1,a+m+1);
reverse(a+1,a+m+1);
for(int i=1;i<=t;i++){
int cntt=1;
for(int qw=1;qw<=p;qw++){
tot+=a[cntt];
cntt++;
}
if(l<tot){
pi+=l;
pi-=tot;
}
tot=0;
}
cout<<pi;
return 0;
}
30分
调完必关