結果

問題 No.3459 Defeat Slimes
コンテスト
ユーザー aqua
提出日時 2026-02-28 16:36:01
言語 C++23
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=c++23 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
WA  
実行時間 -
コード長 1,733 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 4,446 ms
コンパイル使用メモリ 353,156 KB
実行使用メモリ 14,032 KB
最終ジャッジ日時 2026-02-28 16:36:14
合計ジャッジ時間 12,765 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 20 WA * 10
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <bits/stdc++.h>
using namespace std;

using ll = long long;

bool chmax(auto &a, auto b) { return a < b ? a = b, 1 : 0; }
bool chmin(auto &a, auto b) { return a > b ? a = b, 1 : 0; }

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);

    ll N, Y, Z; cin >> N >> Y >> Z;
    vector<tuple<ll,ll,ll>> S(N); // (L, X, C)
    for (int i = 0; i < N; ++i) cin >> get<2>(S[i]) >> get<0>(S[i]) >> get<1>(S[i]);
    sort(S.begin(), S.end());
    
    int s = 0;
    ll ans = 0;
    priority_queue<pair<ll,ll>> pq;
    for (; s < N && get<0>(S[s]) <= Y; ++s) {
        auto [l, x, c] = S[s];
        pq.push({x, c});
    }
    while (!pq.empty() && Y < Z) {
        // cout << s << ' ' << Y << ' ' << ans << '\n';
        if (s == N) {
            while (!pq.empty()) {
                auto [x, c] = pq.top(); pq.pop();
                ll beat = min((Z - Y + x - 1) / x /* ceil(Z-Y / x) */, c);
                ans += beat;
                Y += x * beat;
                if (Y >= Z) {
                    cout << ans << '\n';
                    return 0;
                }
            }
            cout << -1 << '\n';
            return 0;
        }

        while (!pq.empty() && Y < get<0>(S[s])) {
            auto [x, c] = pq.top(); pq.pop();
            ll beat = min((get<0>(S[s]) - Y + x - 1) / x, c);
            ans += beat;
            Y += x * beat;
            if (beat < c) pq.push({x, c - beat});
        }
        if (Y < get<0>(S[s])) {
            cout << -1 << '\n';
            return 0;
        }
        for (; s < N && get<0>(S[s]) <= Y; ++s) {
            auto [l, x, c] = S[s];
            pq.push({x, c});
        }
    }
    if (Y >= Z) cout << ans << '\n';
    else cout << -1 << '\n';
}
0