-
Notifications
You must be signed in to change notification settings - Fork 0
/
BJ12764.java
64 lines (52 loc) · 1.68 KB
/
BJ12764.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
package BJ;
import java.io.*;
import java.util.*;
public class BJ12764 {
static class Node implements Comparable<Node>{
int a, b;
public Node(int a, int b) {
this.a = a;
this.b = b;
}
@Override
public int compareTo(Node o) {
return this.a-o.a;
}
}
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st;
StringBuilder sb = new StringBuilder();
int N = Integer.parseInt(br.readLine());
Node[] useC = new Node[N];
for (int i = 0; i < N; i++) {
st = new StringTokenizer(br.readLine());
int a = Integer.parseInt(st.nextToken());
int b = Integer.parseInt(st.nextToken());
useC[i] = new Node(a,b);
}
Arrays.sort(useC);
PriorityQueue<Node> pq = new PriorityQueue<>();
PriorityQueue<Integer> seat = new PriorityQueue<>();
List<Integer> ans = new ArrayList<>();
int cnt=0;
for (int i = 0; i < N; i++) {
while (!pq.isEmpty()&&pq.peek().a<=useC[i].a) {
Node now = pq.poll();
seat.add(now.b);
}
if (!seat.isEmpty()){
int nSeat = seat.poll();
ans.set(nSeat,ans.get(nSeat)+1);
pq.add(new Node(useC[i].b,nSeat));
} else {
ans.add(1);
pq.add(new Node(useC[i].b,cnt));
cnt++;
}
}
sb.append(cnt+"\n");
for(int i:ans) sb.append(i+" ");
System.out.print(sb);
}
}