fork download
  1. import java.io.*;
  2. import java.util.Arrays;
  3. import java.util.Comparator;
  4.  
  5. public class Main {
  6.  
  7. public static void main (String[] args) throws IOException {
  8.  
  9. int size = Integer.parseInt(br.readLine());
  10.  
  11. int[][] array = new int[size][2];
  12.  
  13. for(int i=0; i<size; i++) {
  14. String[] input = br.readLine().split(" ");
  15. array[i][0] = Integer.parseInt(input[0]);
  16. array[i][1] = Integer.parseInt(input[1]);
  17. }
  18.  
  19. Arrays.sort(array, Comparator.comparingInt((int[] a) -> a[0]));
  20.  
  21. int endTime = array[0][1];
  22. int result = 0;
  23. for(int i=1; i<size; i++){
  24. // 시간이 겹칠때
  25. if(array[i][0] < endTime){
  26. endTime = Math.min(endTime,array[i][1]);
  27. }else{
  28. endTime = array[i][1];
  29. result++;
  30. }
  31. }
  32. System.out.println(result+1);
  33. }
  34. }
  35.  
Success #stdin #stdout 0.08s 55848KB
stdin
2
1 2
1 1
stdout
1