結果
| 問題 |
No.2957 Combo Deck Builder
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2024-11-08 22:44:58 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 171 ms / 1,000 ms |
| コード長 | 1,193 bytes |
| コンパイル時間 | 3,433 ms |
| コンパイル使用メモリ | 258,852 KB |
| 実行使用メモリ | 20,516 KB |
| 最終ジャッジ日時 | 2024-11-08 22:45:13 |
| 合計ジャッジ時間 | 9,066 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 38 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, x, y) for (auto i = (x); i < (y); i++)
#define RREP(i, x, y) for (auto i = (y) - 1; (x) <= i; i--)
#define ALL(x) (x).begin(), (x).end()
#pragma GCC optimize("O3")
#define size(A) ((A).size())
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
int T=1;
while(T--){
int N;
cin >> N;
vector<ll> K(N), L(N), R(N);
REP(i, 0, N){
cin >> K[i] >> R[i] >> L[i];
K[i]=max<ll>(K[i],0);
}
vector<array<ll, 2>> A, B;
ll ans = 0;
REP(i, 0, N){
if(L[i] > R[i]){
A.push_back({K[i], L[i] - R[i]});
ans += R[i];
}else{
B.push_back({N - K[i], R[i] - L[i]});
ans += L[i];
}
}
sort(ALL(A));
multiset<ll> ms;
REP(i, 0, size(A)){
ms.insert(A[i][1]);
if(size(ms) > A[i][0]){
ms.erase(ms.begin());
}
}
ans += accumulate(ALL(ms), 0LL);
ms.clear();
sort(ALL(B));
REP(i, 0, size(B)){
ms.insert(B[i][1]);
if(size(ms) > B[i][0]){
ms.erase(ms.begin());
}
}
ans += accumulate(ALL(ms), 0LL);
cout << ans << "\n";
}
return 0;
}