|
| 1 | +import java.io.*; |
| 2 | +import java.util.*; |
| 3 | + |
| 4 | +public class Main { |
| 5 | + |
| 6 | + public static void main(String[] args) throws IOException { |
| 7 | + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); |
| 8 | + StringBuffer sb = new StringBuffer(); |
| 9 | + int T = Integer.parseInt(br.readLine()); |
| 10 | + for(int i=0; i<T; i++) { |
| 11 | + StringTokenizer st = new StringTokenizer(br.readLine()); |
| 12 | + int totalTeam = Integer.parseInt(st.nextToken()); |
| 13 | + int totalQuiz = Integer.parseInt(st.nextToken()); |
| 14 | + int teamId = Integer.parseInt(st.nextToken()); |
| 15 | + int logCount = Integer.parseInt(st.nextToken()); |
| 16 | + |
| 17 | + int[][] score = new int[totalTeam+1][totalQuiz+1]; |
| 18 | + int[] submission = new int[totalTeam+1]; |
| 19 | + int[] lastTime = new int[totalTeam+1]; |
| 20 | + Arrays.fill(lastTime, logCount); |
| 21 | + List<Team> teamList = new ArrayList<>(); |
| 22 | + for(int j=0; j<logCount; j++) { |
| 23 | + st = new StringTokenizer(br.readLine()); |
| 24 | + int t = Integer.parseInt(st.nextToken()); |
| 25 | + int q = Integer.parseInt(st.nextToken()); |
| 26 | + int s = Integer.parseInt(st.nextToken()); |
| 27 | + score[t][q] = Math.max(score[t][q], s); |
| 28 | + submission[t]++; |
| 29 | + lastTime[t] = j; |
| 30 | + } |
| 31 | + for(int j=1; j<=totalTeam; j++) { |
| 32 | + int totalScore = 0; |
| 33 | + for(int k=1; k<=totalQuiz; k++) { |
| 34 | + totalScore += score[j][k]; |
| 35 | + } |
| 36 | + teamList.add(new Team(j, totalScore, submission[j], lastTime[j])); |
| 37 | + } |
| 38 | + Collections.sort(teamList); |
| 39 | + |
| 40 | + for(int j=0; j<totalTeam; j++) { |
| 41 | + if(teamId == teamList.get(j).teamId) { |
| 42 | + sb.append(j+1).append('\n'); |
| 43 | + break; |
| 44 | + } |
| 45 | + } |
| 46 | + } |
| 47 | + System.out.print(sb); |
| 48 | + } |
| 49 | + |
| 50 | + public static class Team implements Comparable<Team>{ |
| 51 | + int teamId; |
| 52 | + int score; |
| 53 | + int submissionCount; |
| 54 | + int lastTime; |
| 55 | + |
| 56 | + public Team(int teamId, int score, int count, int time) { |
| 57 | + this.teamId = teamId; |
| 58 | + this.score = score; |
| 59 | + this.submissionCount = count; |
| 60 | + this.lastTime = time; |
| 61 | + } |
| 62 | + |
| 63 | + @Override |
| 64 | + public int compareTo(Team t) { |
| 65 | + if(this.score == t.score) { |
| 66 | + if(t.submissionCount == this.submissionCount) { |
| 67 | + return Integer.compare(this.lastTime, t.lastTime); |
| 68 | + } |
| 69 | + return Integer.compare(this.submissionCount, t.submissionCount); |
| 70 | + } |
| 71 | + return Integer.compare(t.score, this.score); |
| 72 | + } |
| 73 | + } |
| 74 | +} |
0 commit comments