結果
問題 | No.2957 Combo Deck Builder |
ユーザー |
|
提出日時 | 2024-11-09 17:15:47 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 293 ms / 1,000 ms |
コード長 | 928 bytes |
コンパイル時間 | 4,205 ms |
コンパイル使用メモリ | 256,468 KB |
実行使用メモリ | 15,132 KB |
最終ジャッジ日時 | 2024-11-09 17:16:02 |
合計ジャッジ時間 | 14,696 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 38 |
ソースコード
#include <bits/stdc++.h>#define rep(i, n) for (int i = 0; i < (n); ++i)using namespace std;using ll = long long;using P = pair<int, int>;ll f(vector<P> p) {int n = p.size();rep(i, n) p[i].first = min(p[i].first, n);vector<vector<int>> s(n+1);rep(i, n) s[p[i].first].push_back(p[i].second);ll res = 0;priority_queue<int> q;for (int i = n; i >= 1; --i) {for (int x : s[i]) q.push(x);if (q.size()) {res += q.top();q.pop();}}return res;}int main() {int n;cin >> n;ll ans = 0;vector<P> pl, pr;rep(i, n) {int k, l, r;cin >> k >> l >> r;int m = min(l, r);ans += m;l -= m; r -= m;if (r > 0) pr.emplace_back(k, r);else pl.emplace_back(n-k, l);}ans += f(pl);ans += f(pr);cout << ans << '\n';return 0;}