116902024-11-05 12:35:41MagyarKendeSZLGSzöveg egyenetlenségcpp17Accepted 100/100225ms6968 KiB
#include <algorithm>
#include <iostream>
#include <numeric>
#include <vector>

using namespace std;
using ll = long long;

void solve() {
    vector<ll> h(52);
    int Q;
    cin >> Q;
    while (Q--) {
        ll F, K;
        char C;
        cin >> F >> C >> K;

        if (C >= 'a') {
            C -= 'a';
        } else {
            C = C - 'A' + 26;
        }
        h[C] += F;

        auto nh = h;
        sort(nh.begin(), nh.end());

        for (int i = 0; i < 51; i++) {
            if (K <= nh[i]) {
                nh[51] += K;
                nh[i] -= K;
                break;
            } else {
                nh[51] += nh[i];
                K -= nh[i];
                nh[i] = 0;
            }
        }

        ll sum = accumulate(nh.begin(), nh.end(), 0LL),
           result = 0;
        for (int i = 0; i < 52; i++) {
            result += nh[i] * (sum - nh[i]);
        }

        cout << result / 2 << "\n";
    }
}

int main() {
    cin.tie(0), ios::sync_with_stdio(0);
    int T;
    cin >> T;
    while (T--) solve();
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted1ms320 KiB
subtask220/20
2Accepted1ms320 KiB
3Accepted1ms320 KiB
4Accepted1ms320 KiB
5Accepted1ms320 KiB
6Accepted1ms320 KiB
subtask320/20
7Accepted170ms4960 KiB
8Accepted168ms4972 KiB
9Accepted170ms5068 KiB
10Accepted172ms5160 KiB
11Accepted171ms5436 KiB
subtask430/30
12Accepted187ms6208 KiB
13Accepted170ms5048 KiB
14Accepted184ms6456 KiB
15Accepted182ms6712 KiB
16Accepted185ms6968 KiB
subtask530/30
17Accepted225ms6200 KiB
18Accepted170ms5176 KiB
19Accepted207ms6712 KiB
20Accepted208ms6712 KiB
21Accepted197ms6876 KiB