hwooo
BOJ (Java) 1946번: 신입 사원 본문
https://www.acmicpc.net/problem/1946
풀이
두 개의 조건을 비교해야 하므로, 먼저 서류 심사 순으로 순위를 매긴다.
이렇게 되면 서류 심사는 무조건 높은 사람부터 탐색할 수 있으므로, 면접 심사 순위만 비교하면 된다.
현재 지원자의 면접 심사 순위를 저장해두고, 다음 면접자의 순위가 더 높은 경우만 합격시킨다.
Java 코드
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
public class Main {
private static int[] num;
private static int n;
public static void main(String[] args) throws IOException {
BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
String s = bf.readLine();
int T = Integer.parseInt(s);
List<Grade> grades = new ArrayList<>();
for (int t = 0; t < T; t++) {
n = Integer.parseInt(bf.readLine());
for (int i = 0; i < n; i++) {
String[] inputs = bf.readLine().split(" ");
int doc = Integer.parseInt(inputs[0]);
int meet = Integer.parseInt(inputs[1]);
grades.add(new Grade(doc, meet));
}
grades.sort((a, b) ->
Integer.compare(a.document, b.document));
int cnt = 1;
int rate = grades.get(0).meeting;
for (int i = 1; i < n; i++) {
if (rate > grades.get(i).meeting) {
cnt++;
rate = grades.get(i).meeting;
}
}
System.out.println(cnt);
grades.clear();
}
}
private static class Grade {
int meeting;
int document;
public Grade(int meeting, int document) {
this.meeting = meeting;
this.document = document;
}
}
}
'Study > Algorithm' 카테고리의 다른 글
BOJ (Java) 13913번: 숨바꼭질 4 (1) | 2025.06.26 |
---|---|
BOJ (Java) 1806번: 부분합 (0) | 2025.06.24 |
BOJ (Java) 2638번: 치즈 (0) | 2025.06.10 |
BOJ (Java) 16940번: BFS 스페셜 저지 (0) | 2025.06.04 |
BOJ (Java) 10942번: 팰린드롬? (0) | 2025.06.02 |