[BOJ] 1946 신입사원

알파·2022년 7월 12일

서류순위로 오름차순 정렬을 해준 후에 면접순위를 앞쪽에 있는 지원자들의 면접순위와 비교해주면 된다. 만약 앞쪽 지원자보다 면접순위가 낮을 경우 서류와 면접 둘다 순위가 낮게 된다.
최소값을 갱신해서 풀어야 한다.

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Comparator;
import java.util.StringTokenizer;

public class Solution1946 {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int T = Integer.parseInt(br.readLine());
        StringBuilder sb = new StringBuilder();
        int[][] scores;
        for (int i = 0; i < T; i++) {
            int N = Integer.parseInt(br.readLine());
            scores = new int[N][2];
            for (int j = 0; j < N; j++) {
                StringTokenizer st = new StringTokenizer(br.readLine());
                scores[j][0] = Integer.parseInt(st.nextToken());
                scores[j][1] = Integer.parseInt(st.nextToken());
            }

            Arrays.sort(scores, Comparator.comparingInt((int[] o) -> o[0]));
            int cnt = 1;
            int min = scores[0][1];
            for(int j = 1; j < N; j++) {
                if(scores[j][1] < min) {
                    cnt++;
                    min = scores[j][1];
                }
            }
            sb.append(cnt + " ");
        }
        System.out.println(sb);
    }
}
profile
I am what I repeatedly do

0개의 댓글