|
| 1 | +import java.io.BufferedReader; |
| 2 | +import java.io.IOException; |
| 3 | +import java.io.InputStreamReader; |
| 4 | +import java.util.*; |
| 5 | + |
| 6 | +public class SB_8979 { |
| 7 | + static int N, K; |
| 8 | + static List<Nation> nations = new ArrayList<>(); |
| 9 | + private static int medal2Int(int g, int s, int b){ |
| 10 | + return g * 1000000 + s * 1000 + b; |
| 11 | + } |
| 12 | + public static void main(String[] args) throws IOException { |
| 13 | + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); |
| 14 | + StringTokenizer st = new StringTokenizer(br.readLine()); |
| 15 | + |
| 16 | + N = Integer.parseInt(st.nextToken()); |
| 17 | + K = Integer.parseInt(st.nextToken()); |
| 18 | + |
| 19 | + for (int i = 0; i < N; i++) { |
| 20 | + st = new StringTokenizer(br.readLine()); |
| 21 | + int idx = Integer.parseInt(st.nextToken()); |
| 22 | + int g = Integer.parseInt(st.nextToken()); |
| 23 | + int s = Integer.parseInt(st.nextToken()); |
| 24 | + int b = Integer.parseInt(st.nextToken()); |
| 25 | + nations.add(new Nation(idx, medal2Int(g, s, b))); |
| 26 | + } |
| 27 | + |
| 28 | + Collections.sort(nations); |
| 29 | + |
| 30 | + int rank = 1; |
| 31 | + int tmp = 1; // 동점자 처리를 위한 변수(매번 증가) |
| 32 | + int preScore = nations.get(0).score; |
| 33 | + for (Nation cur : nations) { |
| 34 | + if (cur.score != preScore) rank = tmp; // 서로 점수가 다르면 순위 갱신 |
| 35 | + if (cur.idx==K){ // 찾는 나라면 순위 출력 |
| 36 | + System.out.println(rank); |
| 37 | + return; |
| 38 | + } |
| 39 | + tmp++; |
| 40 | + preScore = cur.score; |
| 41 | + } |
| 42 | + } |
| 43 | + |
| 44 | + static class Nation implements Comparable<Nation>{ |
| 45 | + int idx, score; |
| 46 | + |
| 47 | + public Nation(int idx, int score) { |
| 48 | + this.idx = idx; |
| 49 | + this.score = score; |
| 50 | + } |
| 51 | + |
| 52 | + @Override |
| 53 | + public int compareTo(Nation o) { |
| 54 | + return o.score - this.score; |
| 55 | + } |
| 56 | + |
| 57 | + @Override |
| 58 | + public String toString() { |
| 59 | + return "Nation{" + |
| 60 | + "idx=" + idx + |
| 61 | + ", score=" + score + |
| 62 | + '}'; |
| 63 | + } |
| 64 | + } |
| 65 | +} |
0 commit comments