結果

問題 No.3130 Twin's Add Max Min Game
ユーザー Cafe1942
提出日時 2025-04-25 23:14:06
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 48 ms / 2,000 ms
コード長 1,598 bytes
コンパイル時間 1,225 ms
コンパイル使用メモリ 108,180 KB
実行使用メモリ 7,844 KB
最終ジャッジ日時 2025-04-25 23:14:12
合計ジャッジ時間 5,511 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 56
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <iomanip>//小数点出力用
//cout << fixed << setprecision(10) << ans;
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>
using ll = long long;
using namespace std;
#define modPHash (ll)((1LL<<61)-1)
#define modP (ll)998244353
bool chkrng0idx(int pos, int sup) { return (0 <= pos && pos < sup); }
int clk4(int num) { return (num - 2) * (num % 2); }
void yn(bool tf) { cout << (tf ? "Yes\n" : "No\n"); }

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int N;
    cin >> N;
    vector<ll>A(N);
    for (int i = 0;i < N;i++) {
        cin >> A[i];
    }
    sort(A.begin(), A.end());
    int addC = 0;
    int maxC = 0;
    int minC = 0;
    for (int i = 0;i < N;i++) {
        string tmp;
        cin >> tmp;
        switch (tmp[1])
        {
        case 'd'://add
            addC++;
            break;
        case 'a'://max
            maxC++;
            break;
        case 'i'://min
            minC++;
            break;
        }
    }

    ll X = 0;
    if (addC + maxC >= 1) {


        X = A[addC + maxC - 1];
        A[addC + maxC - 1] = A[N - 1];
        if (addC != 0) {
            addC--;
        }
        else {
            maxC--;
        }
        N -= 1;
    }
    for (int i = 0;i < N;i++) {
        if (addC != 0) {
            X += A[i];
            addC--;
        }
        else if (maxC != 0) {
            X = max(X, A[i]);
            maxC--;
        }
        else {
            X = min(X, A[i]);
        }
    }
    cout << X;
    return 0;
}
0