File tree Expand file tree Collapse file tree 1 file changed +40
-0
lines changed
Expand file tree Collapse file tree 1 file changed +40
-0
lines changed Original file line number Diff line number Diff line change 1+ ``` java
2+ import java.util.* ;
3+ import java.io.* ;
4+
5+ public class Main {
6+ static BufferedReader br = new BufferedReader (new InputStreamReader (System . in));
7+ static BufferedWriter bw = new BufferedWriter (new OutputStreamWriter (System . out));
8+ static StringTokenizer st;
9+ static int N ;
10+
11+ public static void main (String [] args ) throws Exception {
12+ N = Integer . parseInt(br. readLine());
13+ PriorityQueue<int[]> pq = new PriorityQueue<> ((a, b) - > {
14+ if (a[1 ] == b[1 ]) {
15+ return a[0 ] - b[0 ];
16+ } else {
17+ return a[1 ] - b[1 ];
18+ }
19+ });
20+ for (int i = 0 ; i < N ; i++ ) {
21+ st = new StringTokenizer (br. readLine());
22+ pq. add(new int [] {Integer . parseInt(st. nextToken()), Integer . parseInt(st. nextToken())});
23+ }
24+ int cnt = 0 ;
25+ int curTime = 0 ;
26+ while (! pq. isEmpty()) {
27+ int [] cur = pq. poll();
28+ if (cur[0 ] >= curTime) {
29+ cnt++ ;
30+ curTime = cur[1 ];
31+ }
32+ }
33+ bw. write(cnt + " " );
34+ bw. close();
35+ }
36+ }
37+
38+
39+
40+ ```
You can’t perform that action at this time.
0 commit comments