結果

問題 No.3130 Twin's Add Max Min Game
コンテスト
ユーザー pockyny
提出日時 2025-07-10 02:09:59
言語 C++17
(gcc 15.2.0 + boost 1.90.0)
コンパイル:
g++-15 -O2 -lm -std=c++17 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 85 ms / 2,000 ms
+ 206µs
コード長 638 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 489 ms
コンパイル使用メモリ 99,512 KB
実行使用メモリ 5,888 KB
最終ジャッジ日時 2026-07-13 02:25:20
合計ジャッジ時間 6,936 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 56
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

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

using namespace std;
typedef long long ll;
int main(){
    int i,n; cin >> n;
    vector<ll> a(n);
    for(i=0;i<n;i++) cin >> a[i];
    int ad = 0,mx = 0,mn = 0;
    for(i=0;i<n;i++){
        string s; cin >> s;
        if(s=="add") ad++;
        if(s=="max") mx++;
        if(s=="min") mn++;
    }
    sort(a.begin(),a.end());
    if(ad==0){
        if(mx==0) cout << 0 << "\n";
        else cout << a[mx - 1] << "\n";
    }else{
        ll x = a[mx + ad - 1];
        for(i=0;i<ad - 1;i++) x += a[i];
        if(mn>0) x = min(x,a[mx + ad]);
        cout << x << "\n";
    }
}
0