結果

問題 No.2957 Combo Deck Builder
コンテスト
ユーザー zjsdut
提出日時 2026-06-25 00:27:47
言語 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,628 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 2,771 ms
コンパイル使用メモリ 346,432 KB
実行使用メモリ 7,548 KB
最終ジャッジ日時 2026-06-25 00:27:59
合計ジャッジ時間 11,746 ms
ジャッジサーバーID
(参考情報)
judge1_1 / judge3_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 21 WA * 17
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

/**
 *    author:  zjs
 *    created: 24.06.2026 22:46:15
**/
#include <bits/stdc++.h>
#include <cassert> // <bits/stdc++.h> does not include cassert since GCC 16.
using namespace std;

#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) 42
#endif

struct Card {
    int c, x, y;
};
bool cmp(Card a, Card b) {
    return a.c < b.c;
}
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int N;
    cin >> N;
    vector<Card> a, b;
    int cnt = 0;
    long long ans = 0;
    for (int i = 0; i < N; i++) {
        int c, x, y;
        cin >> c >> x >> y;
        cnt += x <= y;
        if (x < y)
            a.push_back({c, x, y});
        else if (x > y)
            b.push_back({c, x, y});
        else 
            ans += x;
    }
    sort(a.begin(), a.end(), cmp);
    priority_queue<int, vector<int>, greater<int>> gain;
    for (auto [c, x, y] : a) {
        ans += x;
        int delta = y - x;
        if ((int) gain.size() < c) {
            gain.push(delta);
        } else if (gain.size() && gain.top() < delta) {
            gain.pop();
            gain.push(delta);
        }
    }
    while (gain.size()) {
        ans += gain.top();
        gain.pop();
    }
    sort(b.begin(), b.end(), cmp);
    priority_queue<int> loss;
    for (auto [c, x, y] : b) {
        ans += x;
        int delta = x - y;
        if (cnt < c) {
            loss.push(delta);
        } else if (loss.size() && loss.top() > delta) {
            loss.pop();
            loss.push(delta);
        }
        cnt++;
    }
    while (loss.size()) {
        ans -= loss.top();
        loss.pop();
    }
    cout << ans << '\n';
}
0