UVa 119 - Greedy Gift Givers

Summary
A typical Simulation problem. Follow the instruction carefully.

Explanation
N can be at most 10, so the naive array implementation will do.

Java Solution using HashMap

Python Solution

Gotcha's
Names should be printed in the order they appeared. Put one more line at the end will give your feedback as wrong answer (not presentation error as usual). One trick to avoid this is to print a newline before output the answers for every group except the first group. For example, use a counter,

Input
5 dave laura owen vick amr dave 200 3 laura owen vick owen 500 1 dave amr 150 2 vick owen laura 0 2 amr vick vick 0 0 3 liz steve dave liz 30 1 steve steve 55 2 liz dave dave 0 2 steve liz

Output
dave 302 laura 66 owen -359 vick 141 amr -150

liz -3 steve -24 dave 27

Solution

 * C++: http://acm-solution.blogspot.com/2010/11/acm-uva-119-greedy-gift-givers.html
 * Code All the Problems