Skip to content

Commit ea90bae

Browse files
authored
[20260114] BOJ / P5 / 소방서의 고민 / 한종욱
1 parent e4d62fd commit ea90bae

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
```
2+
import java.io.*;
3+
import java.util.*;
4+
5+
public class Main {
6+
private static final BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
7+
private static final BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
8+
private static final int MOD = 40000;
9+
private static PriorityQueue<Task> pq;
10+
private static int N;
11+
private static long t;
12+
13+
public static void main(String[] args) throws IOException {
14+
init();
15+
16+
while (!pq.isEmpty()) {
17+
Task temp = pq.poll();
18+
t += temp.a*t+temp.b;
19+
t %= MOD;
20+
}
21+
22+
bw.write(t + "\n");
23+
bw.flush();
24+
bw.close();
25+
br.close();
26+
}
27+
28+
private static void init() throws IOException {
29+
N = Integer.parseInt(br.readLine());
30+
31+
pq = new PriorityQueue<>((o1, o2) -> {
32+
if (o1.a == 0 && o2.a == 0) return 0;
33+
if (o1.a == 0) return 1;
34+
if (o2.a == 0) return -1;
35+
return Long.compare(o2.a*o1.b, o1.a*o2.b);
36+
});
37+
38+
for (int i = 1; i <= N; i++) {
39+
StringTokenizer st = new StringTokenizer(br.readLine());
40+
pq.add(new Task(Long.parseLong(st.nextToken()), Long.parseLong(st.nextToken())));
41+
}
42+
}
43+
44+
static class Task {
45+
long a;
46+
long b;
47+
48+
public Task(long a, long b) {
49+
this.a = a;
50+
this.b = b;
51+
}
52+
}
53+
}
54+
```

0 commit comments

Comments
 (0)