結果

問題 No.1739 Princess vs. Dragoness (& AoE)
ユーザー tnakao0123tnakao0123
提出日時 2021-11-13 22:02:36
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 580 ms / 3,000 ms
コード長 1,096 bytes
コンパイル時間 2,349 ms
コンパイル使用メモリ 56,748 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-18 17:30:32
合計ジャッジ時間 13,176 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 465 ms
4,376 KB
testcase_05 AC 469 ms
4,380 KB
testcase_06 AC 112 ms
4,376 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 206 ms
4,380 KB
testcase_09 AC 253 ms
4,376 KB
testcase_10 AC 149 ms
4,376 KB
testcase_11 AC 132 ms
4,380 KB
testcase_12 AC 3 ms
4,376 KB
testcase_13 AC 283 ms
4,380 KB
testcase_14 AC 317 ms
4,380 KB
testcase_15 AC 406 ms
4,376 KB
testcase_16 AC 167 ms
4,380 KB
testcase_17 AC 204 ms
4,376 KB
testcase_18 AC 140 ms
4,376 KB
testcase_19 AC 45 ms
4,376 KB
testcase_20 AC 78 ms
4,380 KB
testcase_21 AC 185 ms
4,380 KB
testcase_22 AC 399 ms
4,376 KB
testcase_23 AC 430 ms
4,380 KB
testcase_24 AC 580 ms
4,376 KB
testcase_25 AC 326 ms
4,376 KB
testcase_26 AC 478 ms
4,376 KB
testcase_27 AC 383 ms
4,380 KB
testcase_28 AC 491 ms
4,380 KB
testcase_29 AC 425 ms
4,376 KB
testcase_30 AC 499 ms
4,380 KB
testcase_31 AC 542 ms
4,376 KB
testcase_32 AC 440 ms
4,380 KB
testcase_33 AC 2 ms
4,376 KB
testcase_34 AC 2 ms
4,380 KB
testcase_35 AC 2 ms
4,380 KB
testcase_36 AC 2 ms
4,376 KB
testcase_37 AC 2 ms
4,380 KB
testcase_38 AC 2 ms
4,380 KB
testcase_39 AC 3 ms
4,376 KB
testcase_40 AC 2 ms
4,376 KB
testcase_41 AC 2 ms
4,376 KB
testcase_42 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

/* -*- coding: utf-8 -*-
 *
 * 1739.cc:  No.1739 Princess vs. Dragoness (& AoE) - yukicoder
 */

#include<cstdio>
#include<queue>
#include<algorithm>
 
using namespace std;

/* constant */

const int MAX_N = 100000;

/* typedef */

typedef long long ll;

/* global variables */

int hs[MAX_N];

/* subroutines */

bool check(int n, int a, int b, int x, int y, int k) {
  priority_queue<int> q;
  for (int i = 0; i < n; i++)
    if (hs[i] > k) q.push(hs[i] - k);
  
  while (a > 0 && ! q.empty()) {
    int h = q.top(); q.pop();
    if (h >= x) {
      int d = min(a, h / x);
      h -= d * x, a -= d;
    }
    else
      h -= x, a--;
    if (h > 0) q.push(h);
  }

  ll sum = 0;
  while (! q.empty()) sum += q.top(), q.pop();
  return (sum <= (ll)y * b);
}

/* main */

int main() {
  int n, a, b, x, y;
  scanf("%d%d%d%d%d", &n, &a, &b, &x, &y);
  for (int i = 0; i < n; i++) scanf("%d", hs + i);

  int k0 = -1, k1 = *max_element(hs, hs + n);
  while (k0 + 1 < k1) {
    int k = (k0 + k1) / 2;
    if (check(n, a, b, x, y, k)) k1 = k;
    else k0 = k;
  }

  printf("%d\n", k1);
  return 0;
}
0