greedy gift givers
You are to determine, for a group of gift-giving friends, how much more each person gives than they receive (and vice versa for those that view gift giving with cynicism). In this problem, each person sets aside some money for gift-giving and divides this money evenly among all those to whom gifts are given. However, in any group of friends, some people are more giving than others (or at least may have more acquaintances) and some people have more money than others.
Given a group of friends, the money each person in the group spends on gifts, and a (sub)list of friends to whom each person gives gifts: write a program that determines how much more (or less) each person in the group gives than they receive.
Input File Structure:
The input is a group of gift-givers which consists of several lines:
* The number of people in the group,
* A list of the names of each person in the group,
* A line for each person in the group consisting of
* The name of the person
* The amount of money spent on gifts
* The number of people to whom gifts are given
* The names of those to whom gifts are given.
All names are lower-case letters; there are no more than 10 people in a group; no name is more than 12 characters in length. Money is a non-negative integer less than or equal to 2000.
Output
The name of each person in the group should be printed on a line followed by the net gain (or loss) received (or spent), (money in - money out) by the person. Names in a group should be printed in the same order in which they first appear in the input. All gifts are integers. Each person gives the same integer amount of money to each friend to whom any money is given, and gives as much as possible. Any money not given is kept and is not part of a person's ``net worth'' printed in the output.
Test Case 1
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
Output:
dave 302
laura 66
owen -359
vick 141
amr -150
Test Case 2
Input:
3
liz steve dave
liz 30 1 steve
steve 55 2 liz dave
dave 0 2 steve liz
Output:
liz -3
steve -24
dave 27
Test Case 3
input:
10
russ megan nick pete jerry jerome barbara superbhacker john jess
russ 2000 7 nick megan pete jerry barbara jerome jess
john 500 4 jess russ megan superbhacker
superbhacker 1000 3 jerry jerome barbara
jerry 660 2 russ pete
nick 0 0
jerome 0 3 jerry barbara superbhacker
barbara 1200 3 jerry jerome nick
megan 253 2 russ john
jess 450 3 john megan superbhacker
pete 1999 6 russ nick jerry jerome barbara superbhacker
output:
russ -1081
megan 308
nick 1018
pete -1383
jerry 691
jerome 1351
barbara -249
superbhacker -391
john -224
jess -40
Updated: