11690 | 2024-11-05 12:35:41 | MagyarKendeSZLG | Szöveg egyenetlenség | cpp17 | Accepted 100/100 | 225ms | 6968 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();
}
Subtask | Sum | Test | Verdict | Time | Memory | ||
---|---|---|---|---|---|---|---|
subtask1 | 0/0 | ||||||
1 | Accepted | 1ms | 320 KiB | ||||
subtask2 | 20/20 | ||||||
2 | Accepted | 1ms | 320 KiB | ||||
3 | Accepted | 1ms | 320 KiB | ||||
4 | Accepted | 1ms | 320 KiB | ||||
5 | Accepted | 1ms | 320 KiB | ||||
6 | Accepted | 1ms | 320 KiB | ||||
subtask3 | 20/20 | ||||||
7 | Accepted | 170ms | 4960 KiB | ||||
8 | Accepted | 168ms | 4972 KiB | ||||
9 | Accepted | 170ms | 5068 KiB | ||||
10 | Accepted | 172ms | 5160 KiB | ||||
11 | Accepted | 171ms | 5436 KiB | ||||
subtask4 | 30/30 | ||||||
12 | Accepted | 187ms | 6208 KiB | ||||
13 | Accepted | 170ms | 5048 KiB | ||||
14 | Accepted | 184ms | 6456 KiB | ||||
15 | Accepted | 182ms | 6712 KiB | ||||
16 | Accepted | 185ms | 6968 KiB | ||||
subtask5 | 30/30 | ||||||
17 | Accepted | 225ms | 6200 KiB | ||||
18 | Accepted | 170ms | 5176 KiB | ||||
19 | Accepted | 207ms | 6712 KiB | ||||
20 | Accepted | 208ms | 6712 KiB | ||||
21 | Accepted | 197ms | 6876 KiB |