Codechef challenges have three divisions. In one challenge, there are NN problems in each division, but some problems may be shared among multiple divisions. Each problem is uniquely identified by a code — a string containing only uppercase English letters. Each participant can only submit in one of the divisions.
Chef wants to find the number of correct solutions, in total among all 33 divisions, for each problem. Given a list of NN problem codes with the numbers of correct solutions for each problem in each division, find the total number of correct solutions for each problem and sort them in non-decreasing order.
Sample Input 1
3
1
A 1
B 2
C 3
2
AA 1
AB 1
AB 1
AC 1
AC 1
AD 1
1
Z 100
Z 100
Z 100
Sample Output 1
1 2 3
1 1 2 2
300
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define pii pair<int,int>
#define deb(x) cout << #x << ” ” << x << endl
#define all(x) (x).begin(),(x).end()
#define fio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define rep(x,start,end) for(auto x=(start)-((start)>(end));x!=(end)-((start)>(end));((start)<(end)?x++:x–))
#include<climits>
const int MOD = 1e9 + 7;
const ll INF = 1e12;
ll mod(ll a) {
if (a >= 0)
return a;
else
return (-1 * a);
}
void swap(ll a, ll b) {
ll temp = a;
a = b;
b = temp;
}
ll power(ll a, ll b) {
ll result = 1;
while (b) {
if (b % 2)
result = (result % MOD) * (a % MOD);
a = ((a % MOD) * (a % MOD)) % MOD;
b = b / 2;
}
return result;
}
bool power_check(ll a) {
bool ans = true;
while (a > 1) {
if (a % 2 == 0) {
a = a / 2;
}
else {
ans = false;
break;
}
}
return ans;
}
void solve() {
unordered_map<string,int> mp;
int n;
cin >>n;
for (int i = 0; i < 3*n; ++i)
{
string s;
cin >> s;
int v;
cin >> v;
mp[s] += v;
}
vector<int> v;
for(auto x:mp){
v.pb(x.second);
}
sort(all(v));
for(int x:v){
cout << x << ” “;
}
cout << endl;
return;
}
int main() {
#ifndef ONLINE_JUDGE
freopen(“input.txt”, “r”, stdin);
freopen(“output.txt”, “w”, stdout);
#endif
fio
//cout << 1000000000 * 1000000000;
int qqq;
cin >> qqq;
//qqq = 1;
while (qqq–) {
solve();
}
//ll ans = 1LL << 64;
//cout << ans << endl;
return 0;
}