結果

問題 No.2957 Combo Deck Builder
ユーザー vjudge1
提出日時 2024-11-13 15:24:56
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 119 ms / 1,000 ms
コード長 1,288 bytes
コンパイル時間 4,503 ms
コンパイル使用メモリ 286,988 KB
実行使用メモリ 7,952 KB
最終ジャッジ日時 2024-11-13 15:25:10
合計ジャッジ時間 13,709 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 38
権限があれば一括ダウンロードができます

ソースコード

diff #

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

const int N = 2e5 + 10;

int n, c[N], x[N], y[N];

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

    cin >> n;
    for(int i = 1; i <= n; i ++)
        cin >> c[i] >> x[i] >> y[i];

    vector<int> l, r;
    long long ans = 0;
    for(int i = 1; i <= n; i ++) {
        ans += min(x[i], y[i]);
        if (x[i] > y[i]) r.push_back(i);
        else if(x[i] < y[i]) l.push_back(i);
    }

    sort(l.begin(), l.end(), [](int a, int b) {return c[a] < c[b];});
    sort(r.begin(), r.end(), [](int a, int b) {return c[a] > c[b];});

    {
        priority_queue<int> q;
        for(int i = 1; i <= n; i ++) {
            while(r.size() && i > c[r.back()]) {
                q.push(x[r.back()] - y[r.back()]);
                r.pop_back();
            }
            if(q.size()) {
                ans += q.top();
                q.pop();
            }
        }
    }

    {
        priority_queue<int> q;
        for(int i = n; i >= 1; i --) {
            while(l.size() && i <= c[l.back()]) {
                q.push(y[l.back()] - x[l.back()]);
                l.pop_back();
            }
            if(q.size()) {
                ans += q.top();
                q.pop();
            }
        }
    }
    cout << ans << "\n";
}
0