P1201 [USACO1.1] Greedy Gift Givers

Description

In a group of $n$ 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 $n$, the number of people. - The next $n$ lines each contain a string, the name of a person. Then there are $n$ 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]$, and the second is $g_i$, the number of recipients of this person's gifts. If $g_i \neq 0$, the next $g_i$ lines list the recipients' names, one per line.

Output Format

Output $n$ 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+1$ of the input. The amount given out is always an integer. Specifically, suppose a giver distributes $n$ dollars to $m$ people at once; then each person should receive $\lfloor n/m \rfloor$ dollars. Any leftover money is returned to the giver.

Explanation/Hint

Constraints $1 \le n \le 10$. Translation adapted from NOCOW. USACO Training Section 1.1. Translated by ChatGPT 5