File tree Expand file tree Collapse file tree 1 file changed +55
-0
lines changed
Expand file tree Collapse file tree 1 file changed +55
-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 PriorityQueue<Task> pq;
9+ private static int[][] task;
10+ private static int N;
11+
12+ public static void main(String[] args) throws IOException {
13+ init();
14+
15+ while (!pq.isEmpty()) {
16+ bw.write(pq.poll().index + " ");
17+ }
18+ bw.flush();
19+ bw.close();
20+ br.close();
21+ }
22+
23+ private static void init() throws IOException {
24+ N = Integer.parseInt(br.readLine());
25+ task = new int[N+1][2];
26+
27+ for (int i = 1; i <= N; i++) {
28+ StringTokenizer st = new StringTokenizer(br.readLine());
29+ task[i][0] = Integer.parseInt(st.nextToken());
30+ task[i][1] = Integer.parseInt(st.nextToken());
31+ }
32+
33+ pq = new PriorityQueue<>((o1, o2) -> {
34+ if (o1.val != o2.val) return Double.compare(o2.val, o1.val);
35+ return Integer.compare(o1.index, o2.index);
36+ });
37+
38+ for (int i = 1; i <= N; i++) {
39+ pq.add(new Task(i, (double)task[i][1]/task[i][0], task[i][0]));
40+ }
41+ }
42+
43+ static class Task {
44+ int index;
45+ double val;
46+ int time;
47+
48+ public Task(int index, double val, int time) {
49+ this.index = index;
50+ this.val = val;
51+ this.time = time;
52+ }
53+ }
54+ }
55+ ```
You can’t perform that action at this time.
0 commit comments