結果

問題 No.2957 Combo Deck Builder
コンテスト
ユーザー zjsdut
提出日時 2026-06-25 00:49:26
言語 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
結果
AC  
実行時間 64 ms / 1,000 ms
コード長 1,582 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 3,224 ms
コンパイル使用メモリ 346,296 KB
実行使用メモリ 7,968 KB
最終ジャッジ日時 2026-06-25 00:49:55
合計ジャッジ時間 8,694 ms
ジャッジサーバーID
(参考情報)
judge3_1 / judge2_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 38
権限があれば一括ダウンロードができます

ソースコード

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;
    long long ans = 0;
    for (int i = 0; i < N; i++) {
        int c, x, y;
        cin >> c >> 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);
    for (auto [c, x, y] : views::reverse(b)) {
        ans += y;
        int delta = x - y;
        if (N - (int) gain.size() - 1 >= c) {
            gain.push(delta);
        } else if (gain.size() && gain.top() < delta) {
            gain.pop();
            gain.push(delta);
        }
    }
    while (gain.size()) {
        ans += gain.top();
        gain.pop();
    }
    cout << ans << '\n';
}
0