結果

問題 No.1071 ベホマラー
ユーザー Tsukasan_z46Tsukasan_z46
提出日時 2020-06-06 03:26:58
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,086 bytes
コンパイル時間 3,079 ms
コンパイル使用メモリ 203,540 KB
実行使用メモリ 4,892 KB
最終ジャッジ日時 2023-08-23 08:37:34
合計ジャッジ時間 4,845 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 WA -
testcase_11 AC 19 ms
4,388 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 18 ms
4,576 KB
testcase_22 WA -
testcase_23 AC 18 ms
4,652 KB
testcase_24 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REPLL(i, n) for (ll i = 0; i < (ll)(n); i++)
using namespace std;
template<class T>inline bool chmax(T &a, const T &b){if(a < b){a = b; return 1;}return 0;}
template<class T>inline bool chmin(T &a, const T &b){if(a > b){a = b; return 1;}return 0;}
typedef long long ll;

// yukicoder No.1071 ベホマラー
// 2020.06.06
// Kの商の繰り上げ、昇順に並び替え、右側から累積和、O(N)

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll N, K, X, Y; cin >> N >> K >> X >> Y;
  vector<ll> A(N);
  REPLL(i, N){
    cin >> A[i]; A[i]--;
    A[i] = (A[i]+(K-1))/K;
  }
  sort(A.begin(), A.end());
  vector<ll> AA(N);
  for(ll i = N-1; i >= 0; i--){
    if(i == N-1){
      AA[i] = A[i];
    }else{
      AA[i] = AA[i+1]+A[i];
    }
  }

  ll ans = 1e18;
  ans = min(ans, A[N-1]*Y);
  REPLL(i, N){
    if(AA[i] > 1e9) continue;
    if(i == 0){
      ans = min(ans, AA[i]*X);
    }else{
      ans = min(ans, A[i-1]*Y + (AA[i]-A[i-1]*(N-i))*X);
    }
  }
  cout << ans << endl;
}
0