#include #include #include #include using namespace std; struct s { int score; string word; }; int compare(const void *x, const void *y) { return ((s*)y)->score - ((s*)x)->score; } void insertionSort(int *top, s tag[]) { int j; s tmp; for (int i = 1; i < *top; ++i) { tmp = tag[i]; for (j = i - 1; j >= 0 && tag[j].word > tmp.word && tag[j].score == tmp.score; --j) tag[j + 1] = tag[j]; tag[j + 1] = tmp; } } int main() { int N, M, S, top = 0, k; string tmp; s tag[10000]; cin >> N; for (int i = 0; i < N; ++i) { scanf("%*d%d%d", &M, &S); for (int j = 0; j < M; ++j) { cin >> tmp; for (k = 0; k < top; ++k) { if (tag[k].word == tmp) break; } if (k == top) { tag[top].word = tmp; tag[top].score = S; ++top; } else tag[k].score += S; } } qsort(tag, top, sizeof(s), compare); insertionSort(&top, tag); for (int i = 0; i < 10 && i < top; ++i) cout << tag[i].word << " " << tag[i].score << endl; }