結果

問題 No.1739 Princess vs. Dragoness (& AoE)
ユーザー siman
提出日時 2021-12-22 18:50:00
言語 C++17(clang)
(17.0.6 + boost 1.87.0)
結果
AC  
実行時間 1,059 ms / 3,000 ms
コード長 1,001 bytes
コンパイル時間 1,320 ms
コンパイル使用メモリ 143,304 KB
実行使用メモリ 5,852 KB
最終ジャッジ日時 2024-09-16 13:47:51
合計ジャッジ時間 17,498 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 40
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cassert>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <climits>
#include <map>
#include <queue>
#include <set>
#include <cstring>
#include <vector>

using namespace std;
typedef long long ll;

ll N, A, B, X, Y;
vector<ll> H;

bool f(ll k = 0) {
  priority_queue <ll> pque;

  for (int i = 0; i < N; ++i) {
    pque.push(max(0LL, H[i] - k));
  }

  for (int i = 0; i < A; ++i) {
    ll h = pque.top();
    pque.pop();
    pque.push(h - X);
  }

  ll sum = 0;
  while (not pque.empty()) {
    ll h = pque.top();
    pque.pop();
    sum += max(0LL, h);
  }

  return (sum <= B * Y);
}

int main() {
  cin >> N >> A >> B >> X >> Y;
  H.resize(N);

  for (int i = 0; i < N; ++i) {
    cin >> H[i];
  }

  if (f()) {
    cout << 0 << endl;
    return 0;
  }

  ll ng = 0;
  ll ok = LLONG_MAX;
  while (abs(ok - ng) >= 2) {
    ll k = (ok + ng) / 2;

    if (f(k)) {
      ok = k;
    } else {
      ng = k;
    }
  }

  cout << ok << endl;

  return 0;
}

0