Codeforces Round #215 (Div. 2) A. Sereja and Coat Rack

时间:2023-12-06 13:58:26
#include <iostream>
#include <vector>
#include <algorithm> using namespace std; int main(){
int n,d;
cin >> n >>d;
vector<int>a(n);
for(int i = ; i < n ; ++ i )
cin >>a[i];
int m;
cin >> m;
sort(a.begin(),a.end());
int sum = ;
if(m <=n){
for(int i = ; i < m; ++ i)
sum+=a[i];
}
else{
for(int i = ; i < n; ++ i)
sum+=a[i];
sum -= d*(m-n);
}
cout<<sum<<endl;
return ;
}