結果
問題 |
No.3130 Twin's Add Max Min Game
|
ユーザー |
👑 |
提出日時 | 2025-03-05 22:05:41 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 148 ms / 2,000 ms |
コード長 | 1,273 bytes |
コンパイル時間 | 4,145 ms |
コンパイル使用メモリ | 291,328 KB |
実行使用メモリ | 8,608 KB |
最終ジャッジ日時 | 2025-03-05 22:05:58 |
合計ジャッジ時間 | 16,710 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 56 |
ソースコード
#include <bits/stdc++.h> using namespace std; int main(){ int N; cin >> N; vector<int> A(N); for (int i = 0; i < N; i++){ cin >> A[i]; } sort(A.begin(), A.end()); string dummy; getline(cin, dummy); string line; getline(cin, line); unordered_map<string, int> S; istringstream iss(line); string token; while(iss >> token){ S[token]++; } if(S["add"] == N){ long long total = accumulate(A.begin(), A.end(), 0LL); cout << total << endl; return 0; } else if(S["max"] == N){ cout << A.back() << endl; return 0; } else if(S["min"] == N){ cout << 0 << endl; return 0; } int countMin = S["min"]; int index = N - countMin - 1; long long ans = A[index]; A.erase(A.begin() + index); if(S["add"] > 0){ S["add"]--; } else { S["max"]--; } for (int a : A){ if(S["add"] > 0){ ans += a; S["add"]--; } else if(S["max"] > 0){ ans = max(ans, (long long)a); S["max"]--; } else { ans = min(ans, (long long)a); break; } } cout << ans << endl; return 0; }