没啥难度上代码。
#include <bits/stdc++.h>
using namespace std;
struct node {
string id;
int g, lct, lctRank;
};
vector<node> ans;
vector<vector<node>> v;
bool cmp (node a, node b) {
if (a.g != b.g) return a.g > b.g;
return a.id < b.id;
}
int main() {
int n, k, g;
string id;
scanf ("%d", &n);
v.resize(n);
for (int i = 0; i < n; i++) {
scanf ("%d", &k);
for (int j = 0; j < k; j++) {
cin >> id >> g;
v[i].push_back(node{id, g, i + 1, });
}
sort (v[i].begin(), v[i].end(), cmp);
int Rank = 1, pre = v[i][0].g;
for (int j = 0; j < k; j++) {
if (pre == v[i][j].g) {
v[i][j].lctRank = Rank;
}
else {
v[i][j].lctRank = j + 1;
Rank = j + 1;
pre = v[i][j].g;
}
ans.push_back(v[i][j]);
}
}
sort (ans.begin(), ans.end(), cmp);
printf ("%d\n", ans.size());
int rank = 1, pre = ans[0].g;
for (int i = 0; i < ans.size(); i++) {
if (ans[i].g != pre) {
rank = i + 1;
pre = ans[i].g;
}
printf ("%s %d %d %d\n", ans[i].id.c_str(), rank, ans[i].lct, ans[i].lctRank);
}
}