Saturday, June 6, 2015

UVa 119 - Greedy Gift Givers

// UVa 119 - Greedy Gift Givers

#include <string>
#include <iostream>
#include <map>
using namespace std;

int main() {
	int n, t = 0;
	while (cin >> n) {
		t++;
		map<string, signed long long> money;
		string name[10];
		for (int i = 0; i < n; i++)
			cin >> name[i];
		for (int i = 0; i < n; i++) {
			string giver;
			int budget, ppl;
			cin >> giver >> budget >> ppl;
			if (ppl > 0) {
				int each = budget / ppl;
				for (int j = 0; j < ppl; j++) {
					string receiver;
					cin >> receiver;
					money[receiver] += each;
				}
				money[giver] -= each * ppl;
			}
		}
		if (t > 1)
			cout << endl;
		for (int i = 0; i < n; i++)
			cout << name[i] << " " << money[name[i]] << endl;
	}
	return 0;
}

No comments:

Post a Comment