개발자 톡
연습문제 톡
강의실 배정
이거 타임아웃같은데 뭐가문제일까요?
- 등록일
- 2024-01-29 16:15:02
- 조회수
- 284
- 작성자
- pelor7317
import java.io.*; import java.util.*; public class Main { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int N = Integer.parseInt(br.readLine()); int arr[][] = new int[N][2]; for(int i =0; i<N; i++){ StringTokenizer st = new StringTokenizer(br.readLine()); arr[i][0] = Integer.parseInt(st.nextToken()); arr[i][1] = Integer.parseInt(st.nextToken()); } Arrays.sort(arr, new Comparator<int[]>() { public int compare(int[] o1, int[] o2) { if(o1[0] == o2[0]) return o1[1] - o2[1]; return o1[0] - o2[0]; } }); int fend = arr[0][1]; int result = 1; for(int i = 1; i < N; i++) { if(fend > arr[i][0]) { continue; }else { ++result; fend = arr[i][1]; } } System.out.print(result); } }
#강의실_배정