import java.io.*; import java.util.StringTokenizer; class Person { int num; int Totaltime; int[] penalties; int[] successProb; int numberRight; Person(int id,int numProblems) { num = id; penalties = new int[numProblems]; successProb = new int[numProblems]; for (int i = 0; i < numProblems; i++) { penalties[i] = 0; successProb[i] = 0; } Totaltime = 0; numberRight = 0; } public void updateScore(int prob, int time, int correct) { if (correct == 0) { if (successProb[prob] == 1) return; penalties[prob] += 20; } else if (correct == 1) { if (successProb[prob] == 1) return; numberRight += 1; successProb[prob] = 1; Totaltime += time + penalties[prob]; } } } public class probd { BufferedReader br; BufferedWriter bw; int numDataSets; int currentDataSet; public probd() { try { br = new BufferedReader(new FileReader("probd.in")); bw = new BufferedWriter(new FileWriter("probd.out")); String str = br.readLine(); numDataSets = Integer.parseInt(str); currentDataSet = 1; } catch (Exception e) { e.printStackTrace(); } } public void process() { try { String guide = br.readLine(); //System.out.println("guide: "+guide); StringTokenizer st = new StringTokenizer(guide," "); int numProblems = Integer.parseInt(st.nextToken()); int numSubmissions = Integer.parseInt(st.nextToken()); int numParticipants = Integer.parseInt(st.nextToken()); Person[] peopleList = new Person[numParticipants]; //System.out.println("Initializing"); for (int i = 0; i < numParticipants; i++) { peopleList[i] = new Person(i+1,numProblems); } //System.out.println("Processing submissions"); for (int j = 0; j < numSubmissions; j++) { String str = br.readLine(); //System.out.println("Processing: "+str); st = new StringTokenizer(str+" "," "); int part = Integer.parseInt(st.nextToken()); String let = st.nextToken(); int prob = (int)(let.charAt(0)) - (int)('A'); int time = Integer.parseInt(st.nextToken()); int correct = Integer.parseInt(st.nextToken()); peopleList[part-1].updateScore(prob,time,correct); } peopleList = sort(peopleList); String sol = "Data Set "+currentDataSet+":"; bw.write(sol,0,sol.length()); bw.newLine(); for (int k = 0; k < numParticipants; k++) { sol = peopleList[k].num+" "+peopleList[k].numberRight+" "+peopleList[k].Totaltime; bw.write(sol,0,sol.length()); bw.newLine(); } if (currentDataSet < numDataSets) bw.newLine(); currentDataSet++; } catch (Exception e) { e.printStackTrace(); } } public Person[] sort(Person[] theList) { Person[] list = theList; int num = list.length; for (int index = 0; index < num-1; index++) { int currentWinner = index; for (int j = index+1; j < num; j++) { if ((list[j].numberRight > list[currentWinner].numberRight) || ((list[j].numberRight == list[currentWinner].numberRight) && (list[j].Totaltime < list[currentWinner].Totaltime)) ) currentWinner = j; } Person temp = list[index]; list[index] = list[currentWinner]; list[currentWinner] = temp; } return theList; } public void execute() { for (int i = 0; i < numDataSets; i++) { process(); } try { bw.close(); } catch (Exception e) { e.printStackTrace(); } } public static void main(String[] args) { probd p = new probd(); p.execute(); } }