https://www.acmicpc.net/problem/1946
1946번: 신입 사원
첫째 줄에는 테스트 케이스의 개수 T(1 ≤ T ≤ 20)가 주어진다. 각 테스트 케이스의 첫째 줄에 지원자의 숫자 N(1 ≤ N ≤ 100,000)이 주어진다. 둘째 줄부터 N개 줄에는 각각의 지원자의 서류심사 성
www.acmicpc.net
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Comparator;
import java.util.PriorityQueue;
import java.util.StringTokenizer;
public class Main {
public static void main(String[] args) throws NumberFormatException, IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); // 입력 스트림
StringBuilder sb = new StringBuilder(); // 출력 스트림
StringTokenizer st;
int T = Integer.parseInt(br.readLine()); // 테스트 케이스의 개수
for (int tc = 0; tc < T; tc++) {
int N = Integer.parseInt(br.readLine()); // 지원자의 숫자
PriorityQueue<int[]> pq = new PriorityQueue<>(new Comparator<int[]>() {
@Override
public int compare(int[] a, int[] b) {
return a[0] - b[0]; // 서류성적 기준 오름차순 정렬
}
});
for (int i = 0; i < N; i++) { // 각각의 지원자의 결과
st = new StringTokenizer(br.readLine());
// 서류심사 성적, 면접 성적의 순위 입력받은 값을 우선순위큐에 삽입
pq.offer(new int[] {Integer.parseInt(st.nextToken()), Integer.parseInt(st.nextToken())});
}
int answer = 1; // 선발할 수 있는 신입사원의 최대 인원 수
int current = pq.poll()[1]; // 현재 면접 순위
while (!pq.isEmpty()) {
int[] info = pq.poll();
if (info[1] < current) { // 지원자의 면접 순위가 현재 순위보다 낮으면
answer++; // 인원수 1증가시키고
current = info[1]; // 현재 순위 갱신
}
if (info[1] == 1) { // 만약 면접 1위이면 더이상 볼필요없음
break; // 중단
}
}
sb.append(answer).append("\n");
}
System.out.print(sb);
}
}
'백준' 카테고리의 다른 글
BOJ[JAVA] 6603 로또 (0) | 2023.09.10 |
---|---|
BOJ[JAVA] 1012 유기농배추 (0) | 2023.09.03 |
BOJ[JAVA] 2615 오목 (0) | 2023.08.21 |
BOJ[JAVA] 4949 균형잡힌 세상 (0) | 2023.07.31 |
BOJ[JAVA] 2607 비슷한 단어 (0) | 2023.07.31 |