-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathJim and the Orders.java
36 lines (35 loc) · 1.2 KB
/
Jim and the Orders.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
import java.io.*;
import java.util.*;
public class Solution {
public static void main(String[] args) throws IOException {
StringBuffer sb = new StringBuffer();
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
final short N = Short.parseShort(br.readLine());
final Node[] nodes = new Node[N];
for(short i = 0; i < N; ++i){
final String[] input = br.readLine().split(" ");
final int T = Integer.parseInt(input[0]);
final int D = Integer.parseInt(input[1]);
nodes[i] = new Node(i+1, T + D);
}
Arrays.sort(nodes, new Comparator<Node>(){
public int compare(Node a, Node b){
return (a.data < b.data) ? -1 :
(a.data > b.data) ? 1 :
(a.id < b.id) ? -1 : 1;
}
});
for(int i = 0; i < N; ++i){
sb.append(nodes[i].id).append(" ");
}
System.out.print(sb);
}
public static class Node{
final public int id;
final public int data;
public Node(final int id, final int data){
this.id = id;
this.data = data;
}
}
}