結果

問題 No.1739 Princess vs. Dragoness (& AoE)
ユーザー monkukui2monkukui2
提出日時 2021-11-12 21:39:05
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 351 ms / 3,000 ms
コード長 2,688 bytes
コンパイル時間 3,103 ms
コンパイル使用メモリ 161,324 KB
実行使用メモリ 5,556 KB
最終ジャッジ日時 2023-08-17 00:25:18
合計ジャッジ時間 10,593 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 324 ms
5,556 KB
testcase_05 AC 333 ms
5,508 KB
testcase_06 AC 45 ms
4,672 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 172 ms
4,428 KB
testcase_09 AC 233 ms
5,252 KB
testcase_10 AC 104 ms
4,380 KB
testcase_11 AC 15 ms
4,376 KB
testcase_12 AC 9 ms
4,376 KB
testcase_13 AC 32 ms
4,380 KB
testcase_14 AC 233 ms
4,952 KB
testcase_15 AC 336 ms
5,504 KB
testcase_16 AC 90 ms
4,380 KB
testcase_17 AC 164 ms
4,380 KB
testcase_18 AC 127 ms
4,388 KB
testcase_19 AC 98 ms
4,380 KB
testcase_20 AC 12 ms
4,380 KB
testcase_21 AC 224 ms
5,084 KB
testcase_22 AC 297 ms
5,184 KB
testcase_23 AC 351 ms
5,368 KB
testcase_24 AC 349 ms
5,352 KB
testcase_25 AC 289 ms
5,500 KB
testcase_26 AC 49 ms
4,772 KB
testcase_27 AC 310 ms
5,484 KB
testcase_28 AC 49 ms
4,728 KB
testcase_29 AC 319 ms
5,404 KB
testcase_30 AC 338 ms
5,424 KB
testcase_31 AC 49 ms
4,724 KB
testcase_32 AC 48 ms
4,796 KB
testcase_33 AC 1 ms
4,380 KB
testcase_34 AC 2 ms
4,380 KB
testcase_35 AC 1 ms
4,376 KB
testcase_36 AC 2 ms
4,380 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 #

#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;
}
0