69032023-12-19 15:55:30111Szöveg egyenetlenségcpp17Accepted 100/100684ms4160 KiB
#include <bits/stdc++.h>
using namespace std;

#define int long long
#define double long double

#define pii pair<int, int>

signed main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
#ifdef CB
	freopen("in.txt", "r", stdin);
//	freopen("out.txt", "w", stdout);
#endif
	int T;
	cin >> T;
	while (T--) {
		int Q;
		cin >> Q;
		vector<int> c(150);
		for (int i = 0; i < Q; i++) {
			int F, K;
			char C;
			cin >> F >> C >> K;
			c[C] += F;
			vector<int> v;
			for (char j = 'A'; j <= 'z'; j++) {
				if (c[j]) {
					v.push_back(c[j]);
				}
			}
			sort(v.begin(), v.end());
			int j = 0;
			while (j < v.size() - 1 && v[j] <= K) {
				K -= v[j];
				v.back() += v[j];
				v[j] = 0;
				j++;
			}
			v.back() += K;
			v[j] -= K;
			int ans = 0;
			for (char j = 0; j < v.size(); j++) {
				for (char k = j + 1; k < v.size(); k++) {
					ans += v[j] * v[k];
				}
			}
			cout << ans << '\n';
		}
	}
	return 0;
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted3ms1860 KiB
subtask220/20
2Accepted3ms2092 KiB
3Accepted3ms2176 KiB
4Accepted3ms2416 KiB
5Accepted3ms2628 KiB
6Accepted3ms2660 KiB
subtask320/20
7Accepted97ms2988 KiB
8Accepted97ms3104 KiB
9Accepted97ms3100 KiB
10Accepted98ms3268 KiB
11Accepted100ms3100 KiB
subtask430/30
12Accepted261ms3208 KiB
13Accepted97ms3312 KiB
14Accepted259ms3376 KiB
15Accepted257ms3320 KiB
16Accepted257ms3656 KiB
subtask530/30
17Accepted646ms3884 KiB
18Accepted97ms3792 KiB
19Accepted684ms3948 KiB
20Accepted625ms3956 KiB
21Accepted616ms4160 KiB