Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- data = open("26_demo.txt").readlines()
- s, n = map(int, data[0].split())
- a = list(map(int, data[1:]))
- a.sort()
- cur_sum = 0
- first_answ = 0
- for i in range(n):
- cur_sum += a[i]
- if cur_sum <= s:
- first_answ = i + 1
- else:
- cur_sum -= a[i]
- break
- print(first_answ)
- cur_sum -= a[first_answ - 1]
- for i in range(n - 1, -1, -1):
- if cur_sum + a[i] <= s:
- print(a[i])
- break
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement