백준

백준 1946 신입 사원(Java)

Park DJ 2023. 2. 18. 12:40

https://www.acmicpc.net/problem/1946

 

1946번: 신입 사원

첫째 줄에는 테스트 케이스의 개수 T(1 ≤ T ≤ 20)가 주어진다. 각 테스트 케이스의 첫째 줄에 지원자의 숫자 N(1 ≤ N ≤ 100,000)이 주어진다. 둘째 줄부터 N개 줄에는 각각의 지원자의 서류심사 성

www.acmicpc.net


 

Java 코드

 


import java.util.Scanner;
import java.util.Arrays;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    StringBuilder sb = new StringBuilder();

    int t = sc.nextInt();
 
    for(int i = 0; i < t; i++) {
      int count = 1;
      int n = sc.nextInt();
      int arr[] = new int[n + 1];
      
      for(int j = 0; j < n; j++) {
        int a = sc.nextInt();
        int b = sc.nextInt();
        arr[a] = b;
      }
      int num = arr[1];

      for(int j = 2; j <= n; j++) {
        if(arr[j] < num) {
          count++;
          num = arr[j];
        }
      }
      sb.append(count+"\n");
    }

   System.out.println(sb);
  }
}