사용 알고리즘: 그리디
사용 언어: java
package ssafyRoom2_Monthly_Silver_Random_Defense;
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int T = sc.nextInt();
for (int test = 0; test < T; test++) {
int students = sc.nextInt();
int answer = 1;
List<int[]> list = new ArrayList<>();
for (int i = 0; i < students; i++) {
list.add(new int[] {sc.nextInt(), sc.nextInt()});
}
Collections.sort(list, (a, b) -> a[0] - b[0] );
int rank = list.get(0)[1];
for (int i = 1; i < students; i++) {
if(rank > list.get(i)[1]) {
answer++;
rank = list.get(i)[1];
}
}
System.out.println(answer);
}
}
}
입력값이 점수가 아니라 등수임을 유의!
'알고리즘 > 백준' 카테고리의 다른 글
5212_지구 온난화 (1) | 2025.06.16 |
---|---|
6236_용돈 관리 (1) | 2025.06.15 |
16918_봄버맨 (0) | 2025.06.14 |
1417_국회의원 선거 (1) | 2025.06.09 |
2458_키 순서 (1) | 2025.05.06 |