結果

問題 No.1071 ベホマラー
ユーザー tsushimatsushima
提出日時 2020-06-06 00:08:24
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 25 ms / 2,000 ms
コード長 1,289 bytes
コンパイル時間 1,972 ms
コンパイル使用メモリ 204,864 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-22 18:56:37
合計ジャッジ時間 3,413 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repr(i, a, n) for (int i = n - 1; i >= a; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

const ll MAX = 9223372036854775807;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);

  ll n, k, x, y;
  cin >> n >> k >> x >> y;
  vector<int> a(n), count(n);
  rep(i, 0, n) {
    cin >> a[i];
    a[i]--;
    count[i] = (a[i] + k - 1) / k;
  }

  ll singlev = 0;
  rep(i, 0, n) { singlev += (a[i] + k - 1) / k; }
  bool is_use = false;
  if (singlev <= MAX / x) {
    singlev *= x;
    is_use = true;
  }

  sort(count.rbegin(), count.rend());
  ll ans = MAX, mul = 1, acc = 0;
  rep(i, 0, n) {
    if (i > 0) {
      acc += (count[i - 1] - count[i]) * mul;
      mul++;
    }

    ll single = acc * x;
    ll multi = count[i] * y;

    // 乗算のオーバーフロー検知
    if (acc > MAX / x || count[i] > MAX / y)
      continue;

    // 加算のオーバーフロー検知
    if (single > MAX - multi)
      continue;
    chmin(ans, single + multi);
  }

  if (is_use)
    cout << min(ans, singlev) << endl;
  else
    cout << ans << endl;
}
0