結果

問題 No.2623 Room Allocation
ユーザー GOTKAKOGOTKAKO
提出日時 2024-02-09 21:38:57
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 69 ms / 2,000 ms
コード長 977 bytes
コンパイル時間 2,282 ms
コンパイル使用メモリ 213,240 KB
実行使用メモリ 20,660 KB
最終ジャッジ日時 2024-02-09 21:39:01
合計ジャッジ時間 4,432 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 2 ms
6,676 KB
testcase_03 AC 2 ms
6,676 KB
testcase_04 AC 2 ms
6,676 KB
testcase_05 AC 2 ms
6,676 KB
testcase_06 AC 37 ms
11,496 KB
testcase_07 AC 37 ms
11,496 KB
testcase_08 AC 37 ms
11,496 KB
testcase_09 AC 37 ms
11,496 KB
testcase_10 AC 7 ms
12,560 KB
testcase_11 AC 7 ms
12,560 KB
testcase_12 AC 5 ms
7,872 KB
testcase_13 AC 5 ms
7,872 KB
testcase_14 AC 58 ms
20,660 KB
testcase_15 AC 33 ms
6,784 KB
testcase_16 AC 9 ms
6,676 KB
testcase_17 AC 2 ms
6,676 KB
testcase_18 AC 33 ms
6,912 KB
testcase_19 AC 32 ms
7,808 KB
testcase_20 AC 35 ms
7,680 KB
testcase_21 AC 35 ms
8,064 KB
testcase_22 AC 26 ms
6,676 KB
testcase_23 AC 16 ms
6,676 KB
testcase_24 AC 33 ms
6,676 KB
testcase_25 AC 30 ms
8,064 KB
testcase_26 AC 4 ms
6,676 KB
testcase_27 AC 69 ms
18,252 KB
testcase_28 AC 27 ms
11,516 KB
testcase_29 AC 16 ms
9,484 KB
testcase_30 AC 69 ms
17,140 KB
testcase_31 AC 6 ms
6,676 KB
testcase_32 AC 9 ms
10,156 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int N,X,Y; cin >> N >> X >> Y;
    int room = X+Y;
    vector<vector<pair<long long,char>>> sepa(room);
    for(int i=0; i<N; i++){
        int p; cin >> p;
        char c; cin >> c;
        sepa.at(i%room).push_back({p,c});
    }

    long long answer = 0;
    vector<long long> A,B;
    for(auto se : sepa){
        long long a = 0,b = 0;
        for(auto [p,c] : se){
            if(c == 'A') a += p;
            else b += p;
        }
        if(a > b) A.push_back(a-b),answer += a;
        else if(a == b) answer += b;
        else B.push_back(b-a),answer += b;
    }
    sort(A.begin(),A.end()); sort(B.begin(),B.end());

    if(A.size() > X){
        while(X--) A.pop_back();
        for(auto a : A) answer -= a;
    }
    if(B.size() > Y){
        while(Y--) B.pop_back();
        for(auto b : B) answer -= b;
    }
    cout << answer << endl;
}
0