• 생각

후보자 배열을 만들어 준 뒤 index를 서류 성적, value를 면접 성적으로하면 서류 성적으로 오름차순으로 정렬이 된다. 정렬이 된 상태에서 구해주면 구하긴 쉬워진다.

 

  • 코드

정답 코드 : index를 이용해 오름차순 정렬해준 후 답을 도출.

 

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayDeque;
import java.util.Deque;
import java.util.StringTokenizer;

public class Main {
	static int T;
	static StringBuilder sb;

	public static void main(String[] args) throws Exception {
		SetData();
		System.out.println(sb);
	}

	private static void SetData() throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st = null;

        T = Integer.parseInt(br.readLine());
        sb = new StringBuilder();

        for (int i = 0; i < T; i++) {
            int N = Integer.parseInt(br.readLine());
            int[] candidates = new int[N + 1];
            for (int j = 0; j < N; j++) {
            	st = new StringTokenizer(br.readLine());
                candidates[Integer.parseInt(st.nextToken())] = Integer.parseInt(st.nextToken());
            }

            int count = 1;
            int interviewRank = candidates[1];

            for (int j = 2; j <= N; j++) {
                if (interviewRank >= candidates[j]) {
                    interviewRank = candidates[j];
                    count++;
                }
            }

            sb.append(count + "\n");
        }
	}
}

+ Recent posts