#include #include #include using namespace std; bool compare(pair tag1, pair tag2){ if(tag1.second != tag2.second){ return tag1.second > tag2.second; }else{ return tag1.first < tag2.first; } } int main(){ int N; cin >> N; map scoreboard; for(int i = 0; i < N; i++){ int No, M, S; cin >> No >> M >> S; for(int j = 0; j < M; j++){ string Tag; cin >> Tag; scoreboard[Tag] += S; } } pair scoreboard_array[scoreboard.size()]; int count = 0; for(auto i: scoreboard){ scoreboard_array[count] = i; count++; } sort(scoreboard_array, scoreboard_array + scoreboard.size(), compare); for(int i = 0; i < min(10, int(scoreboard.size())); i++){ cout << scoreboard_array[i].first << " " << scoreboard_array[i].second << endl; } }