-
Notifications
You must be signed in to change notification settings - Fork 0
/
BJ_12764_싸지방준하.java
69 lines (60 loc) · 1.97 KB
/
BJ_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
package Baekjoon;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;
/*
* 사용시간을 pq 로 받아야함.
* */
public class BJ_12764_싸지방준하 {
static class Time implements Comparable<Time>{
int s,e;
public Time(int s, int e){
this.s = s;
this.e = e;
}
@Override
public int compareTo(Time o) {
if(this.s == o.s)
return this.e - o.e;
return this.s - o.s;
}
}
static int N;
static int[] count;
static PriorityQueue<Time> times = new PriorityQueue<>();
static int[] endTimes;
public static void main(String[] args) throws IOException {
BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
N = Integer.parseInt(bf.readLine());
count = new int[N];
endTimes = new int[N];
StringTokenizer st = null;
for(int i = 0 ; i < N;i++){
st = new StringTokenizer(bf.readLine());
times.add(new Time(Integer.parseInt(st.nextToken()),Integer.parseInt(st.nextToken())));
}
int comCount = 0; // 현재 사용하고 있는 컴퓨터 수
while(!times.isEmpty()){
Time now = times.poll();
boolean flag = false;
for(int j = 0;j<comCount;j++){
if(endTimes[j] < now.s){
count[j]++;
endTimes[j] = now.e;
flag = true;
break;
}
}
if(!flag) {
count[comCount]++;
endTimes[comCount++] = now.e;
}
}
StringBuilder sb = new StringBuilder();
sb.append(comCount).append("\n");
for(int i = 0; i <comCount;i++)
sb.append(count[i]+" ");
System.out.println(sb.toString());
}
}