|
| 1 | +import java.io.*; |
| 2 | +import java.util.*; |
| 3 | + |
| 4 | +public class YJ_8979 { |
| 5 | + static class Nation implements Comparable<Nation> { |
| 6 | + int name; |
| 7 | + int gold; |
| 8 | + int silver; |
| 9 | + int bronze; |
| 10 | + |
| 11 | + public Nation(int name, int gold, int silver, int bronze) { |
| 12 | + this.name = name; |
| 13 | + this.gold = gold; |
| 14 | + this.silver = silver; |
| 15 | + this.bronze = bronze; |
| 16 | + } |
| 17 | + |
| 18 | + @Override |
| 19 | + public int compareTo(Nation o) { |
| 20 | + if(this.gold == o.gold){ |
| 21 | + if(this.silver == o.silver){ |
| 22 | + return o.bronze - this.bronze; |
| 23 | + } |
| 24 | + return o.silver - this.silver; |
| 25 | + } |
| 26 | + return o.gold - this.gold; |
| 27 | + } |
| 28 | + } |
| 29 | + |
| 30 | + static PriorityQueue<Nation> pq = new PriorityQueue<>(); |
| 31 | + public static void main(String[] args) throws IOException { |
| 32 | + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); |
| 33 | + StringTokenizer st = new StringTokenizer(br.readLine()); |
| 34 | + int N = Integer.parseInt(st.nextToken()); |
| 35 | + int K = Integer.parseInt(st.nextToken()); |
| 36 | + |
| 37 | + for(int i=0; i<N; i++){ |
| 38 | + st = new StringTokenizer(br.readLine()); |
| 39 | + int nation = Integer.parseInt(st.nextToken()); |
| 40 | + int gold = Integer.parseInt(st.nextToken()); |
| 41 | + int silver = Integer.parseInt(st.nextToken()); |
| 42 | + int bronze = Integer.parseInt(st.nextToken()); |
| 43 | + pq.offer(new Nation(nation, gold, silver, bronze)); |
| 44 | + } |
| 45 | + |
| 46 | + System.out.println(findRank(K)); |
| 47 | + } |
| 48 | + |
| 49 | + static int findRank(int K){ |
| 50 | + int rank = 1; |
| 51 | + Nation prev = pq.poll(); |
| 52 | + if(prev.name == K){ |
| 53 | + return rank; |
| 54 | + } |
| 55 | + |
| 56 | + int same = 0; |
| 57 | + while(!pq.isEmpty()){ |
| 58 | + Nation nation = pq.poll(); |
| 59 | + //동점일 경우 |
| 60 | + if(prev.gold == nation.gold && prev.silver == nation.silver && prev.bronze == nation.bronze){ |
| 61 | + same++; |
| 62 | + }else { |
| 63 | + rank++; |
| 64 | + rank += same; |
| 65 | + same = 0; |
| 66 | + } |
| 67 | + |
| 68 | + if(nation.name == K){ |
| 69 | + break; |
| 70 | + } |
| 71 | + prev = nation; |
| 72 | + } |
| 73 | + return rank; |
| 74 | + } |
| 75 | +} |
0 commit comments