File tree Expand file tree Collapse file tree 1 file changed +54
-0
lines changed
Expand file tree Collapse file tree 1 file changed +54
-0
lines changed Original file line number Diff line number Diff line change 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+ ```
You can’t perform that action at this time.
0 commit comments