백준 - 신입 사원

greenTea·2023년 8월 4일
0
public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st;
        int T = Integer.parseInt(br.readLine());
        for (int i = 0; i < T; i++) {
            int N = Integer.parseInt(br.readLine());
            List<Node> list = new ArrayList<>();

            for (int j = 0; j < N; j++) {
                st = new StringTokenizer(br.readLine());
                int f1 = Integer.parseInt(st.nextToken());
                int f2 = Integer.parseInt(st.nextToken());
                list.add(new Node(f1, f2));
            }

            list.sort(Comparator.comparing(a -> a.f1));

            int ans = 1;
            int num = list.get(0).f2;
            for (int j = 1; j < list.size(); j++) {
                int f2 = list.get(j).f2;
                if (num > f2) {
                    num = f2;
                    ans++;
                }

            }

            System.out.println(ans);


        }
    }

    static class Node {
        private int f1;
        private int f2;

        public Node(int f1, int f2) {
            this.f1 = f1;
            this.f2 = f2;
        }
    }
}
  1. 먼저 서류값을 기준으로 오름차순 정렬을 해줍니다.
  2. 정렬된 상태에서 면접값을 기준으로 해당 문제를 판단하면 되는데 이미 서류값을 기준으로 정렬을 한 상태에서 면접값이 상위에 있는 값보다도 높다면 해당 지원자는 2개의 값이 높은 걸로 판단할 수 있기에 가능한 풀이입니다.
  3. 만약 내려가다가 자신보다도 면접값이 작은 지원자를 만난다면 최소 비교값을 해당 값으로 변경해주면 됩니다.
  4. 이후 해당 값을 제출하면 정답이 나오게 됩니다.

출처 : 백준 - 신입 사원

profile
greenTea입니다.

0개의 댓글