Back
Close

Settling accounts

Statement

 Goal

A group of friends go on a trip together. Some of them have paid some of the expenses. When they get home, they have to share the costs equally and calculate who owes how much.
Input
Line 1: n_participants, integer, the number of participants.
Line 2: The names of the participants, space-separated.
Line 3: n_expenses, integer, the number of expenses paid by members of the groups.
Next n_expenses lines: name amount (integer), separated by a space. The name of the group member who paid, and the amount of the expense.
Output
n_participants lines: The name of the participant and the amount they owe or are owed, in the same order as the input. Prefix the amount with plus + if they are owed or minus - if they owe.
Constraints
1 ≤ n_participants ≤ 10.
0 ≤ n_expenses ≤ 32.
0 ≤ amount ≤ 131072.

The sum of expenses is divisible by the number of participants.
The names are single capital letters.
Example
Input
3
A B C
2
A 30
C 60
Output
A 0
B -30
C +30

Game modes
Fastest, Shortest, Reverse

Test cases
3 people 2 expenses Test
Input
3 A B C 2 A 30 C 60
Output
A 0 B -30 C +30

3 people 2 expenses validator Validator
Input
3 X Y Z 2 X 45 Z 90
Output
X 0 Y -45 Z +45

2 people Test
Input
2 H P 3 H 100 P 1 H 99
Output
H +99 P -99

2 people validator Validator
Input
2 J K 3 J 12 K 9 J 21
Output
J +12 K -12

6 people 5 expenses Test
Input
6 A B C D E F 5 A 12 B 11 C 15 A 20 F 2
Output
A +22 B +1 C +5 D -10 E -10 F -8

6 people 5 expenses validator Validator
Input
6 B C D E F G 5 B 13 C 12 D 16 B 21 G 4
Output
B +23 C +1 D +5 E -11 F -11 G -7

Lonely trip Test
Input
1 A 5 A 9 A 42 A 1348 A 1 A 157
Output
A 0

Lonely trip validator Validator
Input
1 B 6 B 10 B 43 B 13490 B 1 B 1577 B 17
Output
B 0

Share no expenses Test
Input
3 D E F 0
Output
D 0 E 0 F 0

Share no expenses validator Validator
Input
4 W X Y Z 0
Output
W 0 X 0 Y 0 Z 0

Shuffled Test
Input
7 S H U F L E D 3 S 9 D 11 L 8
Output
S +5 H -4 U -4 F -4 L +4 E -4 D +7

Shuffled validator Validator
Input
4 X K C D 4 X 1 C 9 K 2 K 8
Output
X -4 K +5 C +4 D -5

Solution language

Solution

Stub generator input