-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathArgus.java
57 lines (49 loc) · 1.29 KB
/
Argus.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
package com.priorityqueue;
import java.io.*;
import java.util.*;
//uva 1203
public class Argus {
static BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
static BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(System.out));
static PriorityQueue<Registration> argus = new PriorityQueue<>((t1, t2) -> {
if(t1.callAt == t2.callAt) {
return t1.id - t2.id;
}
return t1.callAt - t2.callAt;
});
static int k;
public static void main(String[] args) throws Exception{
String data, input[];
while(true) {
while(!(data = reader.readLine()).equals("#")) {
input = data.split("\\s+");
argus.add(new Registration(Integer.parseInt(input[1]), Integer.parseInt(input[2]), Integer.parseInt(input[2])));
}
k = Integer.parseInt(reader.readLine());
process();
break;
}
writer.close();
reader.close();
}
static void process() throws Exception{
Registration reg;
for(int i = 0; i < k; i++) {
reg = argus.poll();
writer.write(String.format("%s\n", reg.id));
reg.callAt += reg.period;
argus.add(reg);
}
}
static class Registration {
int id;
int period;
int callAt;
public Registration(int id, int period, int callAt) {
super();
this.id = id;
this.period = period;
this.callAt = callAt;
}
}
}