-
Notifications
You must be signed in to change notification settings - Fork 0
/
12764번 싸지방에 간 준하.java
76 lines (69 loc) · 1.99 KB
/
12764번 싸지방에 간 준하.java
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
//12764번 싸지방에 간 준하.java
package boj20220105;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.PriorityQueue;
import java.util.StringTokenizer;
public class 싸지방에_간_준하_12764 {
static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
static StringTokenizer st;
static StringBuilder sb = new StringBuilder();
static class time implements Comparable<time>{
int P;
int Q;
time(int P, int Q){
this.P=P;
this.Q=Q;
}
@Override
public int compareTo(time o) {
return Integer.compare(this.P, o.P);
}
}
static class computer implements Comparable<computer>{
int Q;
int index;
computer(int Q, int index){
this.Q=Q;
this.index=index;
}
@Override
public int compareTo(computer o) {
return Integer.compare(this.Q, o.Q);
}
}
public static void main(String[] args) throws NumberFormatException, IOException {
int N = Integer.parseInt(br.readLine());
PriorityQueue<time> times = new PriorityQueue<>();
for(int i=0;i<N;i++) {
st = new StringTokenizer(br.readLine()," ");
int P = Integer.parseInt(st.nextToken());
int Q = Integer.parseInt(st.nextToken());
times.add(new time(P, Q));
}
PriorityQueue<computer> comEndTime = new PriorityQueue<>();
PriorityQueue<Integer> nextCom = new PriorityQueue<>();
int[] comIndex = new int[100001];
int comCount=0;
for(int i=0;i<N;i++) {
while(!comEndTime.isEmpty() && times.peek().P > comEndTime.peek().Q) {
nextCom.add(comEndTime.poll().index);
}
if(nextCom.isEmpty()) {
comEndTime.add(new computer(times.poll().Q, comCount));
comIndex[comCount]++;
comCount++;
}
else {
comEndTime.add(new computer(times.poll().Q, nextCom.peek()));
comIndex[nextCom.poll()]++;
}
}
sb.append(comCount+"\n");
for(int i=0;i<comCount;i++) {
sb.append(comIndex[i]+" ");
}
System.out.println(sb.toString());
}
}