USACO 1.1.2 – Greedy Gift Givers

int main() {
	int sum , n, N, d;
	vector<string> v;
	map<string, int> m, g;
	string s, t;
	fin >> N;
	for (int i = 0; i < N; i++) {
		fin >> s;
		v.push_back(s);
		m[s] = g[s] = 0;
	}
	for (int i = 0; i < N; i++) {
		fin >> s >>  sum >> n;
		if(!n) continue;
		g[s] = sum,  d = sum/n, m[s] = m [s] + sum - n*d;
		for (int j = 0; j < n; j++) {
			fin >> t;
			m[t] = m[t] + d;
		}
	}
	for (int i = 0; i < N; i++)
		fout << v[i] << " " <<  m[v[i]] - g[v[i]] << endl;

	return 0;
}
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: