~cpp 
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <map>

using namespace std;

map<string,int> List;
vector<string> ManList;

int max_num = 0;
ifstream fin("gift1.in");
ofstream fout("gift1.out");

void Free();
void InputData();
void OutputData();

int main()
{
	InputData();
	OutputData();
	fout.close();
	fin.close();
	return 0;
}

void InputData()
{
	fin >> max_num;

	string name;
	for(int k = 0 ; k < max_num ; ++k)
	{
		fin >> name;	
		List[name] = 0;
		ManList.push_back(name);
	}

	string tempname;
	int tempmoney;
	int numto;
	for(int k = 0 ; k < max_num ; ++k)
	{
		fin >> tempname;
		fin >> tempmoney;
		fin >> numto;

		List[tempname] -= tempmoney;

		string tempname2;
		int dist;
		if(numto)
			dist = tempmoney / numto;
		for(int j = 0 ; j < numto ; ++j )
		{
			fin >> tempname2;
			List[tempname2] += dist;
		}

		if(tempmoney - dist * numto) 
		{
			List[tempname] += (tempmoney - dist * numto);
		}
	}
}

void OutputData()
{
	for(int i = 0 ; i < max_num ; ++i)
		fout << ManList[i] << " " << List[ManList[i]] << endl;
}
Retrieved from http://wiki.zeropage.org/wiki.php/[Lovely]boy^_^/USACO/GreedyGiftGivers
last modified 2021-02-07 05:28:37