結果

問題 No.3681 心の沸騰石
コンテスト
ユーザー rarula
提出日時 2026-09-10 01:41:48
言語 C++23(gcc16)
(gcc 16.1.0 + boost 1.92.0 + ACL)
コンパイル:
g++-16 -O2 -lm -std=c++23 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 1 ms / 2,000 ms
+ 458µs
コード長 958 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 2,994 ms
コンパイル使用メモリ 350,684 KB
実行使用メモリ 6,528 KB
最終ジャッジ日時 2026-09-10 01:41:53
合計ジャッジ時間 4,749 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 13
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <bits/stdc++.h>
#define endl '\n'
using namespace std;
using ll = long long;

void solve() {
    ll R, P, Q;
    cin >> R >> P >> Q;
    vector<ll> D(4);
    for (int i = 0; i < 4; i++) cin >> D[i];

    auto judge = [&](ll k) -> bool {
        ll rem = D[3];
        ll need = 0;
        for (int i = 0; i < 3; i++) {
            if (D[i] >= k) rem += D[i] - k;
            else need += k - D[i];
        }
        if (rem < need) return false;
        ll sum = 0;
        sum += need * Q;
        sum += k * P;
        return sum <= R;
    };

    ll ok = 0;
    ll ng = R + 1; // [ok, ng)
    while (ng - ok > 1) {
        ll mid = (ok + ng) / 2;
        if (judge(mid)) {
            ok = mid;
        } else {
            ng = mid;
        }
    }

    cout << ok << endl;
    return;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll T = 1;
    // cin >> T;
    while (T--) {
        solve();
    }
    return 0;
}
0