結果

問題 No.3459 Defeat Slimes
コンテスト
ユーザー dyktr_06
提出日時 2026-02-13 03:41:12
言語 C++17
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=c++17 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 508 ms / 3,000 ms
コード長 1,210 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 2,463 ms
コンパイル使用メモリ 228,420 KB
実行使用メモリ 19,236 KB
最終ジャッジ日時 2026-02-28 13:07:21
合計ジャッジ時間 19,489 ms
ジャッジサーバーID
(参考情報)
judge5 / judge7
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 30
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

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

using P = pair<long long, long long>;

int main(){
    int N;
    long long Y, Z;
    cin >> N >> Y >> Z;
    vector<long long> C(N), L(N), X(N);
    for(int i = 0; i < N; i++){
        cin >> C[i] >> L[i] >> X[i];
    }

    vector<P> border(N);
    for(int i = 0; i < N; i++){
        border[i] = make_pair(L[i], i);
    }
    border.emplace_back(Z, -1);
    sort(border.begin(), border.end());

    priority_queue<P> pq;
    for(int i = 0; i < N; i++){
        if(L[i] <= Y){
            pq.emplace(X[i], C[i]);
        }
    }

    long long cur = Y, ans = 0;
    int k = upper_bound(border.begin(), border.end(), make_pair(cur, 1LL << 60)) - border.begin();
    while(pq.size() && cur < Z){
        auto [nxt, idx] = border[k];
        if(nxt <= cur){
            if(idx != -1){
                pq.emplace(X[idx], C[idx]);
            }
            k++;
            continue;
        }

        auto [x, c] = pq.top();
        pq.pop();
        long long cnt = min((nxt - cur + x - 1) / x, c);
        cur += cnt * x;
        ans += cnt;
        if(cnt != c) pq.emplace(x, c - cnt);
    }

    if(cur < Z) cout << -1 << endl;
    else cout << ans << endl;
}
0