forked from rajatgoyal715/Hackerrank
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJimAndOrders.java
More file actions
33 lines (30 loc) · 854 Bytes
/
JimAndOrders.java
File metadata and controls
33 lines (30 loc) · 854 Bytes
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
package Greedy;
import java.util.*;
import java.io.*;
/*
* @author -- rajatgoyal715
*/
public class JimAndOrders {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
int a[] = new int[n];
String s[]=new String[n+1];
Map<Integer,Integer> map = new TreeMap<Integer,Integer>();
for(int i=0;i<n;i++){
a[i]=sc.nextInt()+sc.nextInt();
s[i+1]=(i+1)+" ";
if(map.get(a[i])!=null){
s[i+1]=s[map.get(a[i])]+s[i+1];
}
map.put(a[i], i+1);
}
Set set = map.entrySet();
Iterator i= set.iterator();
while(i.hasNext()){
Map.Entry me = (Map.Entry)i.next();
int t2=(int)me.getValue();
System.out.print(s[t2]);
}
}
}