結果
問題 | No.1739 Princess vs. Dragoness (& AoE) |
ユーザー |
![]() |
提出日時 | 2021-11-12 21:39:05 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 306 ms / 3,000 ms |
コード長 | 2,688 bytes |
コンパイル時間 | 2,727 ms |
コンパイル使用メモリ | 162,728 KB |
実行使用メモリ | 6,820 KB |
最終ジャッジ日時 | 2024-11-25 17:31:28 |
合計ジャッジ時間 | 8,459 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 40 |
ソースコード
#include "atcoder/all"#include <iostream>#include <cstdio>#include <string>#include <cstring>#include <deque>#include <list>#include <queue>#include <stack>#include <vector>#include <utility>#include <algorithm>#include <map>#include <set>#include <complex>#include <cmath>#include <limits>#include <climits>#include <ctime>#include <cassert>#include <numeric>#include <functional>#include <bitset>#include <cstddef>#include <type_traits>#include <vector>using namespace std;const long long int INF = numeric_limits<long long int>::max() / 4;const int inf = numeric_limits<int>::max() / 4;const long long int MOD1000000007 = 1000000007;const long long int MOD998244353 = 998244353;const double MATH_PI = 3.1415926535897932;template<typename T1, typename T2>inline void chmin(T1 &a, const T2 &b) { if (a > b) a = b; }template<typename T1, typename T2>inline void chmax(T1 &a, const T2 &b) { if (a < b) a = b; }#define lint long long int#define ALL(a) a.begin(),a.end()#define RALL(a) a.rbegin(),a.rend()#define rep(i, n) for(int i=0;i<(int)(n);i++)#define VI vector<int>#define VLL vector<long long>#define VC vector<char>#define VB vector<bool>#define PI pair<int, int>#define PLL pair<long long, long long>#define VPI vector<pair<int, int>>#define VPLL vector<pair<long long, long long>>#define VVI vector<vector<int>>#define VVPI vecor<vector<pair<int, int>>>#define VVPILL vector<vector<pair<int, long long>>>#define SUM(v) accumulate(ALL(v), 0LL)#define MIN(v) *min_element(ALL(v))#define MAX(v) *max_element(ALL(v))bool solve(vector<lint> h, lint a, lint b, lint x, lint y) {// 体力 x 減らすを a 回使えるint n = h.size();for (int i = 0; i < n; i++) {if (a <= 0) break;lint cnt = h[i] / x;if (cnt > a) {cnt = a;}h[i] -= cnt * x;a -= cnt;}sort(RALL(h));// a が許す限り 0 にするfor (int i = 0; i < n; i++) {if (a <= 0) break;h[i] = 0;a--;}// 総和が b * y よりでかいかどうかreturn SUM(h) <= b * y;}int main() {lint n, a, b, x, y; cin >> n >> a >> b >> x >> y;vector<lint> h(n);rep (i, n) cin >> h[i];if (solve(h, a, b, x, y)) {cout << 0 << endl;return 0;}lint ng = 0;lint ok = 1e9;while (ok - ng > 1) {lint k = (ok + ng) / 2;vector<lint> tmp(n);rep (i, n) {tmp[i] = max(h[i] - k, 0LL);}if (solve(tmp, a, b, x, y)) {ok = k;} else {ng = k;}}cout << ok << endl;return 0;}