結果

問題 No.3130 Twin's Add Max Min Game
ユーザー テナガザル
提出日時 2025-04-25 23:18:03
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 1,098 bytes
コンパイル時間 1,177 ms
コンパイル使用メモリ 108,164 KB
実行使用メモリ 7,844 KB
最終ジャッジ日時 2025-04-25 23:19:00
合計ジャッジ時間 9,490 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 36 WA * 20
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#include <map>

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());
    long long ans = 0;
    int cnt[3] = {0};
    for (int i = 0; i < n; ++i)
    {
        string s;
        cin >> s;
        if (s == "add") ++cnt[0];
        else if (s == "max") ++cnt[1];
        else ++cnt[2];
    }
    if (cnt[0] <= 1)
    {
        int ans = 0;
        if (cnt[1] + cnt[0] == 0) ans = 0;
        else ans = a[cnt[1] + cnt[0] - 1];
        cout << ans << endl;
    }
    else if (cnt[0] == n)
    {
        long long ans = 0;
        for (int i = 0; i < n; ++i) ans += a[i];
        cout << ans << endl;
    }
    else
    {
        long long ans;
        if (cnt[1] > 0) ans = min(a[0] + a[cnt[0] + cnt[1] - 1], a[min(n - 1, n - cnt[2])]);
        else
        {
            ans = 0;
            for (int i = 0; i < cnt[0]; ++i) ans += a[i];
            ans = min(ans, (long long)a[n - cnt[2]]);
        }
        cout << ans << endl;
    }
}
0