結果

問題 No.2957 Combo Deck Builder
ユーザー nono00nono00
提出日時 2024-11-09 01:09:48
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 4,658 bytes
コンパイル時間 3,812 ms
コンパイル使用メモリ 269,656 KB
実行使用メモリ 20,092 KB
最終ジャッジ日時 2024-11-09 01:10:06
合計ジャッジ時間 10,960 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,248 KB
testcase_02 AC 2 ms
5,248 KB
testcase_03 AC 2 ms
5,248 KB
testcase_04 AC 2 ms
5,248 KB
testcase_05 AC 2 ms
5,248 KB
testcase_06 AC 138 ms
15,072 KB
testcase_07 AC 138 ms
15,084 KB
testcase_08 AC 138 ms
14,960 KB
testcase_09 AC 137 ms
15,184 KB
testcase_10 AC 136 ms
14,848 KB
testcase_11 AC 143 ms
14,912 KB
testcase_12 AC 136 ms
14,872 KB
testcase_13 AC 136 ms
15,040 KB
testcase_14 AC 127 ms
14,740 KB
testcase_15 AC 130 ms
14,808 KB
testcase_16 AC 130 ms
14,676 KB
testcase_17 AC 130 ms
14,696 KB
testcase_18 AC 128 ms
14,780 KB
testcase_19 AC 157 ms
14,964 KB
testcase_20 AC 128 ms
14,764 KB
testcase_21 AC 129 ms
14,788 KB
testcase_22 AC 129 ms
14,660 KB
testcase_23 AC 129 ms
14,668 KB
testcase_24 AC 127 ms
14,732 KB
testcase_25 AC 128 ms
14,664 KB
testcase_26 AC 143 ms
19,908 KB
testcase_27 AC 167 ms
20,092 KB
testcase_28 AC 145 ms
19,824 KB
testcase_29 AC 140 ms
19,960 KB
testcase_30 WA -
testcase_31 AC 74 ms
14,264 KB
testcase_32 AC 120 ms
20,064 KB
testcase_33 AC 125 ms
19,940 KB
testcase_34 AC 66 ms
8,064 KB
testcase_35 AC 68 ms
8,064 KB
testcase_36 WA -
testcase_37 AC 2 ms
5,248 KB
testcase_38 AC 2 ms
5,248 KB
testcase_39 AC 2 ms
5,248 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
template <class T>
using max_heap = priority_queue<T>;
template <class T>
using min_heap = priority_queue<T, vector<T>, greater<T>>;
#define rep(i, l, r) for (ll i = (l); i < (r); i++)
#define rrep(i, r, l) for (ll i = (r); i-- > (l);)
#define all(x) begin(x), end(x)
template <class T>
bool chmin(T& lhs, T rhs) {
    return lhs > rhs ? (lhs = rhs, true) : false;
}
template <class T>
bool chmax(T& lhs, T rhs) {
    return lhs < rhs ? (lhs = rhs, true) : false;
}
struct IOIO {
    IOIO() {
        cin.tie(0)->sync_with_stdio(0);
    }
} ioio;
template <class S, class T>
ostream& operator<<(ostream& os, const pair<S, T>& p) {
    os << '(' << p.first << ", " << p.second << ')';
    return os;
}
template <class T>
ostream& operator<<(ostream& os, const vector<T>& vs) {
    os << '{';
    rep(i, 0, (int)vs.size()) os << vs[i] << (i + 1 == (int)vs.size() ? "" : ", ");
    os << '}';
    return os;
}
template <class T>
ostream& operator<<(ostream& os, const set<T>& vs) {
    os << '{';
    for (auto it = vs.begin(); it != vs.end(); it++) {
        if (it != vs.begin()) {
            os << ", ";
        }
        os << *it;
    }
    os << '}';
    return os;
}
template <class T, class U>
ostream& operator<<(ostream& os, const map<T, U>& vs) {
    os << '{';
    for (auto it = vs.begin(); it != vs.end(); it++) {
        if (it != vs.begin()) {
            os << ", ";
        }
        os << *it;
    }
    os << '}';
    return os;
}
#ifdef DEBUG
void dump_func() {
    cerr << endl;
}
template <class Head, class... Tail>
void dump_func(Head&& head, Tail&&... tail) {
    cerr << head;
    if (sizeof...(Tail) > 0) {
        cerr << ", ";
    }
    dump_func(std::move(tail)...);
}
#define dump(...) cerr << "[" + string(#__VA_ARGS__) + "] ", dump_func(__VA_ARGS__)
#else
#define dump(...) static_cast<int>(0)
#endif

void solve() {
    int n;
    cin >> n;
    struct Card {
        int i;
        int c;
        ll x, y;
    };
    vector<Card> cards(n);
    rep(i, 0, n) cin >> cards[i].c >> cards[i].x >> cards[i].y, cards[i].i = i;
    ll ans = 0;
    for (auto& card: cards) {
        ll mn = min(card.x, card.y);
        ans += mn;
        card.x -= mn;
        card.y -= mn;
    }
    vector<char> used(n);
    const char X = 'X';
    const char Y = 'Y';
    dump(used);
    {
        min_heap<pair<ll, int>> que;
        vector<Card> a;
        for (auto card: cards)
            if (card.x < card.y) a.push_back(card);
        sort(all(a), [](auto lhs, auto rhs) { return lhs.c < rhs.c; });
        rep(i, 0, ssize(a)) {
            que.emplace(a[i].y, a[i].i);
            if (que.size() > a[i].c) {
                que.pop();
            }
        }
        while (!que.empty()) {
            auto [y, i] = que.top();
            que.pop();
            ans += y;
            used[i] = Y;
        }
        rep(i, 0, ssize(a)) {
            if (used[a[i].i] == 0) {
                used[a[i].i] = X;
                ans += a[i].x;
            }
        }
    }
    dump(used);
    {
        min_heap<pair<int, int>> que;
        vector<Card> a;
        for (auto card: cards) {
            if (card.x == card.y) {
                ans += card.x;
                used[card.i] = Y;
            } else if (card.x > card.y) {
                que.emplace(card.c, card.i);
            }
        }
        int used_num = n - count(all(used), 0);
        while (!que.empty()) {
            auto [c, i] = que.top();
            if (c >= used_num) {
                que.pop();
                ans += cards[i].x;
                used[i] = X;
                used_num++;
            } else {
                break;
            }
        }
    }
    dump(used);
    {
        min_heap<pair<ll, int>> que;
        vector<Card> a;
        rep(i, 0, n) if (used[i] == 0) {
            auto card = cards[i];
            card.c = n - card.c;
            a.push_back(card);
        }
        sort(all(a), [](auto lhs, auto rhs) { return lhs.c < rhs.c; });
        rep(i, 0, ssize(a)) {
            que.emplace(a[i].x, a[i].i);
            if (que.size() > a[i].c) {
                que.pop();
            }
        }
        while (!que.empty()) {
            auto [x, i] = que.top();
            que.pop();
            ans += x;
            used[i] = X;
        }
        rep(i, 0, ssize(a)) {
            if (used[a[i].i] == 0) {
                used[a[i].i] = Y;
                ans += a[i].y;
            }
        }
    }
    dump(used);
    cout << ans << '\n';
}

int main() {
    int t = 1;

    while (t--) solve();
}
0