#include #include #include #include #include #include #include #include #include #include #include #include using namespace std; bool comp(pair &a, pair &b){ if (a.first != b.first) return a.first > b.first; else if (a.second != b.second) return a.second < b.second; } int main() { int n, num; cin >> n; vector> vec; for (int i = 0; i < n; i++){ int m, s; cin >> num >> m >>s; for (int j = 0; j < m; j++){ string tag; cin >> tag; int vs = vec.size(); for (int k = 0; k < vs; k++){ if (vec.at(k).second == tag){ vec.at(k).first += s; break; } if (k == vec.size() - 1) vec.push_back(make_pair(s, tag)); } if (vec.size() == 0) vec.push_back(make_pair(s, tag)); } } sort(vec.begin(), vec.end(), comp); num = 0; for (auto x : vec){ cout << x.second << " " << x.first << endl; num++; if (num == 10) break; } }