-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathA39.java
More file actions
40 lines (31 loc) · 895 Bytes
/
A39.java
File metadata and controls
40 lines (31 loc) · 895 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import java.util.*;
public class A39 {
static class Movie {
int start, end;
Movie(int start, int end) {
this.start = start;
this.end = end;
}
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
Movie[] movies = new Movie[n];
for (int i = 0; i < n; i++) {
int start = sc.nextInt();
int end = sc.nextInt();
movies[i] = new Movie(start, end);
}
// 終了時刻でソート
Arrays.sort(movies, Comparator.comparingInt(m -> m.end));
int count = 0;
int currentTime = 0;
for (Movie m : movies) {
if (m.start >= currentTime) {
count++;
currentTime = m.end;
}
}
System.out.println(count);
}
}