-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathArgus.java
50 lines (43 loc) · 1.22 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
import java.io.*;
import java.util.*;
class Main {
public static void main(String... args) throws IOException {
InputStreamReader isr = new InputStreamReader(System.in);
BufferedReader in = new BufferedReader(isr);
String line;
while ((line = in.readLine()) != null) {
PriorityQueue<Query> queries = new PriorityQueue<Query>();
queries.add(new Query(line, 1));
while (!(line = in.readLine()).equals("#")) {
queries.add(new Query(line, 1));
}
if (queries.size() == 0) {
continue;
}
int K = Integer.parseInt(in.readLine());
StringBuilder sb = new StringBuilder();
for (int i = 0; i < K; i++) {
Query q = queries.poll();
q.mul++;
queries.add(q);
sb.append(q.number + "\n");
}
System.out.print(sb);
}
}
static class Query implements Comparable<Query> {
int number, period, mul;
public Query(String line, int mul) {
String[] vals = line.split(" ");
this.mul = mul;
this.number = Integer.parseInt(vals[1]);
this.period = Integer.parseInt(vals[2]);
}
@Override
public int compareTo(Query that) {
int diff1 = (this.period * this.mul) - (that.period * that.mul);
int diff2 = this.number - that.number;
return (diff1 == 0) ? diff2 : diff1;
}
}
}