-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBOJ_19598.java
More file actions
52 lines (42 loc) · 1.5 KB
/
Copy pathBOJ_19598.java
File metadata and controls
52 lines (42 loc) · 1.5 KB
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
41
42
43
44
45
46
47
48
49
50
51
52
// BOJ - 19598
// Problem Sheet - https://www.acmicpc.net/problem/19598
import java.util.*;
import java.io.*;
public class Main {
static class Meeting implements Comparable<Meeting> {
private final int start;
private final int end;
public Meeting(int start, int end) {
this.start = start;
this.end = end;
}
public int getStart() { return this.start; }
public int getEnd() { return this.end; }
@Override
public int compareTo(Meeting m) {
return this.start - m.getStart();
}
}
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st;
int N = Integer.parseInt(br.readLine());
List<Meeting> meetings = new ArrayList<>(N);
for (int i=0 ; i<N ; i++) {
st = new StringTokenizer(br.readLine());
int start = Integer.parseInt(st.nextToken());
int end = Integer.parseInt(st.nextToken());
meetings.add(new Meeting(start, end));
}
Collections.sort(meetings);
PriorityQueue<Integer> endTimes = new PriorityQueue<>();
for (Meeting meeting : meetings) {
if (!endTimes.isEmpty() && endTimes.peek() <= meeting.getStart()) {
endTimes.poll();
}
endTimes.add(meeting.getEnd());
}
System.out.println(endTimes.size());
br.close();
}
}