結果
| 問題 |
No.1739 Princess vs. Dragoness (& AoE)
|
| コンテスト | |
| ユーザー |
tnakao0123
|
| 提出日時 | 2021-11-13 22:02:36 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 531 ms / 3,000 ms |
| コード長 | 1,096 bytes |
| コンパイル時間 | 2,540 ms |
| コンパイル使用メモリ | 57,080 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-11-28 00:14:53 |
| 合計ジャッジ時間 | 11,004 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 40 |
ソースコード
/* -*- 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;
}
tnakao0123