#P1201. [USACO1.1] 贪婪的送礼者 Greedy Gift Givers
[USACO1.1] 贪婪的送礼者 Greedy Gift Givers
Description
In a group of friends who exchange gifts, GY wants to determine, for each person, how much more money they received than they gave.
In this problem, each person prepares some money for gifts, and that money is evenly divided among the people who will receive gifts from them.
However, in any group of friends, some people will give gifts to more recipients (perhaps because they have more friends), and some people prepare more money.
Given a group of friends (no name is longer than 14 characters), along with how much each person spends on gifts and the list of recipients for each giver, determine for each person the amount of money received minus the amount of money given.
Input Format
- The first line contains a positive integer , the number of people.
- The next lines each contain a string, the name of a person.
Then there are blocks. For each block:
- The first line is the name of the person who will give gifts.
- The second line contains two non-negative integers: the first is the initial amount of money in , and the second is , the number of recipients of this person's gifts.
If , the next lines list the recipients' names, one per line.
Output Format
Output lines. Each line contains a person's name and the amount of money they received minus the amount they gave. The order of names must be the same as in lines 2 through of the input.
The amount given out is always an integer. Specifically, suppose a giver distributes dollars to people at once; then each person should receive dollars. Any leftover money is returned to the giver.
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
dave 302
laura 66
owen -359
vick 141
amr -150
Hint
Constraints
.
Translation adapted from NOCOW.
USACO Training Section 1.1.
Translated by ChatGPT 5
京公网安备 11011102002149号