/*
ID: akshika1
LANG: JAVA
TASK: gift1
*/
import java.io.*;
import java.util.*;
class gift1 {
public static void main(String[] args) throws FileNotFoundException {
Scanner sc = new Scanner(new File("gift1.in"));
PrintWriter pw = new PrintWriter(new File("gift1.out"));
int times = sc.nextInt();
sc.nextLine(); //just to go to the next line
String[] names = new String[times];
int[] original = new int[times];
for (int i = 0; i < times; i++) {
original[i] = -1;
}
int[] values = new int[times];
int value;
int division;
int temptimes = times;
int moneyToBeGiven = 0;
String giver;
for (int i = 0; i < times; i++)
{
names[i] = sc.nextLine();
}
for (int j = 0; j < times; j++) {
giver = sc.nextLine();
String t = sc.nextLine();
String[] temp = new String[2];
temp = t.split(" ");
value = Integer.parseInt(temp[0]);
division = Integer.parseInt(temp[1]);
if (division == 0) {
moneyToBeGiven = 0;
} else {
moneyToBeGiven = (value - (value % division)) / division;;
}
String[] tempArray = new String[division];
for (int i = 0; i < division; i++) {
tempArray[i] = sc.nextLine();
}
for (int k = 0; k < names.length; k++) {
if (giver.equals(names[k])) {
if (original[k] == -1) {
original[k] = value;
}
values[k] += value;
values[k] -= (division * moneyToBeGiven);
break;
}
}
for (int i = 0; i < tempArray.length; i++) {
for (int z = 0; z < names.length; z++) {
if (names[z].equals(tempArray[i])) {
values[z] += moneyToBeGiven;
}
}
}
}
for (int i = 0; i < temptimes; i++) {
pw.println(names[i] + " " + (values[i] - original[i]));
}
pw.close();
System.exit(0);
}
}
No comments:
Post a Comment