結果
問題 |
No.3130 Twin's Add Max Min Game
|
ユーザー |
|
提出日時 | 2025-04-26 04:21:03 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 51 ms / 2,000 ms |
コード長 | 979 bytes |
コンパイル時間 | 4,393 ms |
コンパイル使用メモリ | 253,468 KB |
実行使用メモリ | 7,848 KB |
最終ジャッジ日時 | 2025-04-26 04:21:13 |
合計ジャッジ時間 | 9,406 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 56 |
ソースコード
#include <bits/stdc++.h> #include <algorithm> #include <atcoder/all> using namespace std; using ll = long long; #define rep(i, s, t) for (ll i = s; i < (ll)(t); i++) #define all(x) begin(x), end(x) template <typename T> bool chmin(T& x, T y) { return x > y ? (x = y, true) : false; } template <typename T> bool chmax(T& x, T y) { return x < y ? (x = y, true) : false; } struct IOST { IOST() { ios::sync_with_stdio(false); cin.tie(nullptr); cout << fixed << setprecision(20); } } IOST; void solve() { int n; cin >> n; vector<ll> a(n); rep(i, 0, n) cin >> a[i]; vector<int> d(3); rep(i, 0, n) { string s; cin >> s; if (s == "add") d[0]++; else if (s == "max") d[1]++; else d[2]++; } sort(a.begin(), a.end()); ll t = 0; if (d[0] + d[1] > 0) chmax(t, a[d[0] + d[1] - 1]); if (d[0] > 1) { rep(i, 0, d[0] - 1) t += a[i]; } if (d[2] > 0) chmin(t, a[n - d[2]]); cout << t << "\n"; } int main() { int t = 1; // cin >> t; rep(i, 0, t) solve(); }