File tree Expand file tree Collapse file tree 1 file changed +52
-0
lines changed
Expand file tree Collapse file tree 1 file changed +52
-0
lines changed Original file line number Diff line number Diff line change 1+ ``` java
2+ import java.io.* ;
3+ import java.util.* ;
4+
5+ public class Main {
6+ static class study implements Comparable<study> {
7+ int start, end;
8+
9+ study (int s , int e ) {
10+ start = s;
11+ end = e;
12+ }
13+
14+ @Override
15+ public int compareTo (study o ) {
16+ if (this . start != o. start)
17+ return Integer . compare(this . start, o. start);
18+ return Integer . compare(this . end, o. end);
19+ }
20+ }
21+
22+ public static void main (String [] args ) throws IOException {
23+ BufferedReader br = new BufferedReader (new InputStreamReader (System . in));
24+ StringTokenizer st;
25+ int N = Integer . parseInt(br. readLine());
26+
27+ study[] studies = new study [N ];
28+ for (int i = 0 ; i < N ; i++ ) {
29+ st = new StringTokenizer (br. readLine());
30+ int s = Integer . parseInt(st. nextToken());
31+ int e = Integer . parseInt(st. nextToken());
32+ studies[i] = new study(s, e);
33+ }
34+
35+ Arrays . sort(studies);
36+
37+ PriorityQueue<Integer > pq = new PriorityQueue<> ();
38+ pq. add(studies[0 ]. end);
39+
40+ for (int i = 1 ; i < N ; i++ ) {
41+ int curStart = studies[i]. start;
42+ int curEnd = studies[i]. end;
43+ if (! pq. isEmpty() && pq. peek() <= curStart) {
44+ pq. poll();
45+ }
46+ pq. add(curEnd);
47+ }
48+
49+ System . out. println(pq. size());
50+ }
51+ }
52+ ```
You can’t perform that action at this time.
0 commit comments