Dev.baelanche

[백준 1946] 신입 사원 본문

Data Structure & Algorithm/PS - JAVA

[백준 1946] 신입 사원

baelanche 2019. 5. 31. 16:20
반응형

 

 

선택한 사원의 서류 점수, 면접 점수의 순위가 모두 다른 지원자의 서류 점수, 면접 점수의 순위보다 밀리지만 않으면

채용된다.

 

완전탐색으로 구현하면 시간초과가 나므로 두 점수 순위 중 하나로 정렬한 후 나머지 한 순위만 비교해주면 된다.

 

구조체, 클래스로 점수를 묶어서 정렬해도 되고 배열의 인덱스로 정렬해도 된다.

필자는 입력받을때 정렬된 상태로 받았다.

 

 

public class Main {
    
    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
        
        int t = Integer.parseInt(br.readLine());
        while(t-->0) {
            int n = Integer.parseInt(br.readLine());
            int a[] = new int[n+1];
            for(int i=0; i<n; i++) {
                StringTokenizer st = new StringTokenizer(br.readLine());
                a[Integer.parseInt(st.nextToken())] = Integer.parseInt(st.nextToken());
            }
            int interview = a[1];
            int cnt = 1;
            for(int i=2; i<=n; i++) {
                if(a[i] < interview) {
                    interview = a[i];
                    cnt++;
                }
            }
            bw.write(cnt + "\n");
            bw.flush();
        }
    }
}
반응형

'Data Structure & Algorithm > PS - JAVA' 카테고리의 다른 글

[백준 1541] 잃어버린 괄호  (0) 2019.06.03
[백준 1049] 기타줄  (0) 2019.05.31
[백준 2455] 지능형 기차  (0) 2019.05.31
[백준 10610] 30  (0) 2019.05.31
[백준 14502] 연구소  (0) 2019.05.29
Comments