题目地址 L2-009 抢红包 (25 分)

#include <bits/stdc++.h>
using namespace std;

struct Node{
	int num, count, money;
	Node() {
		this->count = 0;
		this->money = 0;
		this->num = 0;
	}
}N[10010];

int cmp(Node a,Node b) {
	if(a.money != b.money)
		return a.money > b.money; 
	else if(a.count != b.count)
		return a.count > b.count;
	else
		return a.num < b.num;
}

int num, k, n, p, sum;
int main() {
	scanf("%d", &num);
	for(int i = 1; i <= num; i++)
		N[i].num = i;
	for(int i = 1; i <= num; i++) {
		scanf("%d", &k);
		sum = 0;
		for(int j = 0; j < k; j++) {
			scanf("%d %d", &n, &p);
			N[n].money += p;
			N[n].count++;
			sum += p;
		}
		N[i].money -= sum;
	}
	sort(N+1,N+1+num,cmp);
	for(int i = 1; i <= num; i++)
		printf("%d %.2lf\n", N[i].num, N[i].money * 1.0 / 100);
	return 0;
}