Problem :

https://www.hackerrank.com/challenges/jim-and-the-orders/problem


My Solution :

#!/usr/bin/env python3


def jim_orders(orders):
result = [(i, sum(times)) for i, times in enumerate(orders, start=1)]
result = sorted(result, key=lambda x: x[1])
result = [str(x[0]) for x in result]
return ' '.join(result)


n = int(input())
orders = []
for _ in range(n):
orders.append(list(map(int, input().rstrip().split())))
result = jim_orders(orders)
print(result)


Comment :

위 방법은 파이썬의 list comprehension과 lambda 함수를 적절히 활용해본 것이고, 아래 방법은 dictionary를 활용해본 것이다.


My Solution2 :

#!/usr/bin/env python3


def jim_orders(orders):
times = {}
for i, time in enumerate(orders, start=1):
times.setdefault(sum(time), []).append(i)
for time, indexes in sorted(times.items()):
for index in indexes:
yield index


n = int(input())
orders = []
for _ in range(n):
orders.append(list(map(int, input().rstrip().split())))
result = jim_orders(orders)
print(' '.join(map(str, result)))