結果

問題 No.1071 ベホマラー
ユーザー kappybarkappybar
提出日時 2020-06-05 21:47:58
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 1,063 bytes
コンパイル時間 1,782 ms
コンパイル使用メモリ 172,680 KB
実行使用メモリ 6,824 KB
最終ジャッジ日時 2024-12-17 14:13:26
合計ジャッジ時間 3,593 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 5
other AC * 13 WA * 7
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(int)(n);i++)
using namespace std;
using ll = long long ;
using P = pair<int,int> ;
using pll = pair<long long,long long>;
constexpr int INF = 1e9;
constexpr long long LINF = 1e17;
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979323846;

int main(){
    ll n;
    cin >> n ;
    ll k,x,y;
    cin >> k >> x >> y;
    vector<ll> a(n);
    rep(i,n){
        cin >> a[i];
        --a[i];
    }
    sort(a.begin(),a.end());
    rep(i,n) a[i] = (a[i]+k-1)/k;
    //rep(i,n) cout << a[i] << endl;
    vector<ll> cumsum(n,0);
    cumsum[n-1] = a[n-1];
    for(int i=n-2;i>=0;i--) cumsum[i] = cumsum[i+1] + a[i];
    //rep(i,n) cout << cumsum[i] << endl;
    /*
    if(y >= n*x){
        cout << cumsum[0] * x << endl;
        return 0;
    }
    */

    ll ans = cumsum[0] * x;
    rep(i,n-1){
        ll res = a[i] * y;
        res += x * (cumsum[i+1] - (n-i-1)*a[i]);
        ans = min(ans,res);
    }
    ll res = a[n-1] * y;
    ans = min(ans,res);
    cout << ans << endl;
    return 0;
}
0