Hackerrank - Greedy - Jim and the Orders

Jim's Burgers has  hungry burger fans waiting in line. Each unique order, , is placed by a customer at time , and the order takes  units of time to process.
Given the information for all  orders, can you find and print the order in which all  customers will receive their burgers? If two or more orders are fulfilled at the exact same time , sort them by ascending order number.

Input Format
The first line contains a single integer, , denoting the number of orders.
Each of the  subsequent lines contains two space-separated integers describing the respective values of  and for order .
Constraints
Output Format
Print a single line of  space-separated order numbers (recall that orders are numbered from  to ) describing the sequence in which the customers receive their burgers. If two or more customers receive their burgers at the same time, print the smallest order number first.
Sample Input 0
3
1 3
2 3
3 3
Sample Output 0
1 2 3
Explanation 0
Jim has the following orders:
  1. . This order is fulfilled at time .
  2. . This order is fulfilled at time .
  3. . This order is fulfilled at time .
As you can see, order  was fulfilled at time , order  was fulfilled at time , and order  was fulfilled at time . Thus, we print the sequence of order numbers in the order in which they were fulfilled as 1 2 3.
Sample Input 1
5
8 1
4 2
5 6
3 1
4 3
Sample Output 1
4 2 5 1 3
Explanation 1
Jim has the following orders:
  1. . This order is fulfilled at time .
  2. . This order is fulfilled at time .
  3. . This order is fulfilled at time .
  4. . This order is fulfilled at time .
  5. . This order is fulfilled at time .
When we order these by ascending fulfillment time, we get:
  • : order .
  • : order .
  • : order .
  • : order .
  • : order .
We print the ordered numbers in the bulleted listed above as 4 2 5 1 3.
Note: While not demonstrated in these sample cases, recall that any orders fulfilled at the same time must be listed by ascending order number.
Solution :
# Enter your code here. Read input from STDIN. Print output to STDOUT
itt = int(raw_input())
dict = {}
for k in range(1,itt+1):
    dict[k] = sum(map(int, raw_input().split()))
    
new_dict = sorted(dict, key=dict.get)
print " ".join(map(str,new_dict))

Comments

Best Programming language for machine learning.

Popular posts from this blog

Hackerrank - Implementation - Picking Numbers

Hackerrank - Dynamic Programming - The Coin Change Problem