Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from functools import cmp_to_key
- def compare(x, y):
- if x[1] < y[1]:
- return 1
- elif x[1] > y[1]:
- return -1
- else:
- if x[2] < y[2]:
- return -1
- elif x[2] > y[2]:
- return 1
- else:
- if x[0] < y[0]:
- return -1
- elif x[0] > y[0]:
- return 1
- else:
- return 0
- def solution(w, n, arr):
- res = []
- arr.sort(key=cmp_to_key(compare))
- i = 0
- while i < n and w:
- if arr[i][2] <= w:
- res.append(arr[i][0])
- w -= arr[i][2]
- i += 1
- res.sort()
- return res
- w = int(input())
- n = int(input())
- arr = [tuple(map(int, '{} {}'.format(i, input()).split())) for i in range(n)]
- print(*solution(w, n, arr))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement