-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJimandOrders_problem.java
More file actions
37 lines (34 loc) · 1.03 KB
/
JimandOrders_problem.java
File metadata and controls
37 lines (34 loc) · 1.03 KB
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
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Scanner;
import java.util.Set;
public class JimAndTheOrders {
public static void main(String[] args) {
Map<Integer, Integer> hmap = new LinkedHashMap<Integer, Integer>();
Scanner sc = new Scanner(System.in);
int N = sc.nextInt();
for (int i = 1; i <= N; i++) {
int key = i;
int value = sc.nextInt() + sc.nextInt();
hmap.put(key, value);
}
Set<Entry<Integer, Integer>> set = hmap.entrySet();
List<Entry<Integer, Integer>> list = new ArrayList<Entry<Integer, Integer>>(set);
Collections.sort(list, new Comparator<Entry<Integer, Integer>>() {
public int compare(Entry<Integer, Integer> e1, Entry<Integer, Integer> e2) {
return e1.getValue().compareTo(e2.getValue());
}
});
for (Entry<Integer, Integer> i : list) {
System.out.print(i.getKey() + " ");
}
sc.close();
}
}
/**
* @author Pradumn Patel */