#P1201. [USACO1.1] 贪婪的送礼者 Greedy Gift Givers

[USACO1.1] 贪婪的送礼者 Greedy Gift Givers

Description

In a group of nn 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 nn, the number of people.
  • The next nn lines each contain a string, the name of a person.

Then there are nn 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 [0,2000][0, 2000], and the second is gig_i, the number of recipients of this person's gifts.
    If gi0g_i \neq 0, the next gig_i lines list the recipients' names, one per line.

Output Format

Output nn 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 n+1n+1 of the input.

The amount given out is always an integer. Specifically, suppose a giver distributes nn dollars to mm people at once; then each person should receive n/m\lfloor n/m \rfloor 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
1n101 \le n \le 10.

Translation adapted from NOCOW.
USACO Training Section 1.1.

Translated by ChatGPT 5