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

OpenSoucre發表於2013-11-28
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main(){
    int n,d;
    cin >> n >>d;
    vector<int>a(n);
    for(int i = 0; i < n ; ++ i )
        cin >>a[i];
    int m;
    cin >> m;
    sort(a.begin(),a.end());
    int sum = 0;
    if(m <=n){
        for(int i = 0 ; i < m; ++ i)
            sum+=a[i];
    }
    else{
        for(int i = 0 ; i < n; ++ i)
            sum+=a[i];
        sum -= d*(m-n);
    }
    cout<<sum<<endl;
    return 0;
}

 

相關文章