- محدودیت زمان: ۱ ثانیه
- محدودیت حافظه: ۲۵۶ مگابایت
In the dormitory, people will take turns to buy dinner or stuff for dinner. Each night one person goes out to buy and writes details of it on the “Detail Paper”. Details include name of the buyer, amount of money he/she paid and name of the people ate that night. Image below shows a Detail Paper.
At the end of each month everybody have to pay their debts, But everyone get’s so creepy when it comes to money. So they all decided to hire a team from ACM(Abdominal Control Market) of the SBU University.
you are one of the teams participating in ACM Newbies Contest so you have to help them. They only have two rules:
- Only people that ate, should pay (name of them is written in Detail Paper)
- The money paid by everyone on each night must be equal.
ورودی
First line of input contains an integer $T$ indicating number of test cases. Each test case contains an integer $L$, number of lines to follow. $$L \leq 50$$
Each line of test case is as following: A string $S$ name of the buyer followed by an integer $C$ cost of things bought followed by an integer $N$, indicating how many people ate that specific night, Following N space separated strings indicating name of the people that ate that night. It’s guaranteed that C is divisible by N and Each line contains no more than 250 characters.
$$0 \lt C \lt 100, 000$$ $$N \leq 10$$
Each Name contains “A-Z” and “a-z” characters. Names are NOT case-sensitive and length of each name is at most 20 characters.
خروجی
For each test case output “Case #X:” (quotations for clarify) which X is the number of test case.
Then print “Debtors:” (quotations for clarify) and in each line print name of debtors and their liability as following sorted by debtors name in alphabetical order: “S owes D Tomans.” (quotations for clarify)
First alphabetical character of S must be uppercase and rest of alphabetical characters must be lowercase, D is an integer number (money person S must pay).
Then print “Creditors:” (quotations for clarify) and in each line print name of creditors and their credit as following sorted by creditors name in alphabetical order: “S paid D Tomans.” (quotations for clarify)
First alphabetical character of S must be uppercase and rest of alphabetical characters must be lowercase, D is an integer number (money person S must get).
People who don’t have to pay or receive any money are neither Debtor nor Creditor, so their name should not appear in output.
مثالها
ورودی نمونه ۱
2
10
Michel 9200 4 Aden John David Michel
Ashley 8700 3 Ashley Aden John
Ashley 6000 3 Michel John Ashley
Aden 15000 3 Ashley John Aden
Michel 1800 4 Aden David Michel Ashley
David 2200 4 Aden John David Ashley
Aden 29400 3 Aden David Ashley
Aden 8500 4 Aden David Ashley John
John 21000 3 Aden Michel John
Aden 3100 2 Aden Michel
1
Ehsan 4500 1 ehsan
خروجی نمونه ۱
Case #1:
Debtors:
Ashley owes 8125 Tomans.
David owes 13025 Tomans.
John owes 875 Tomans.
Michel owes 2300 Tomans.
Creditors:
Aden paid 24325 Tomans.
Case #2:
Debtors:
Creditors:
ارسال پاسخ برای این سؤال