結果

問題 No.1071 ベホマラー
ユーザー tsushimatsushima
提出日時 2020-06-06 00:00:39
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,298 bytes
コンパイル時間 2,344 ms
コンパイル使用メモリ 203,988 KB
実行使用メモリ 4,508 KB
最終ジャッジ日時 2023-08-22 18:42:17
合計ジャッジ時間 3,631 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 1 ms
4,384 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 1 ms
4,384 KB
testcase_10 WA -
testcase_11 AC 19 ms
4,376 KB
testcase_12 WA -
testcase_13 AC 18 ms
4,376 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 AC 24 ms
4,380 KB
testcase_18 AC 24 ms
4,380 KB
testcase_19 AC 24 ms
4,376 KB
testcase_20 AC 18 ms
4,384 KB
testcase_21 WA -
testcase_22 AC 18 ms
4,376 KB
testcase_23 AC 18 ms
4,380 KB
testcase_24 AC 23 ms
4,380 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); }

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; }
  ll tt = singlev * x;
  bool is_use = false;
  if (tt / x == singlev) {
    singlev *= x;
    is_use = true;
  }

  sort(count.rbegin(), count.rend());
  ll ans = LLONG_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 > LLONG_MAX / x || count[i] > LLONG_MAX / y)
      continue;

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

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