Advertisement
nq1s788

26

Mar 27th, 2024 (edited)
499
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.41 KB | None | 0 0
  1. data = open("26_demo.txt").readlines()
  2. s, n = map(int, data[0].split())
  3. a = list(map(int, data[1:]))
  4. a.sort()
  5. cur_sum = 0
  6. first_answ = 0
  7. for i in range(n):
  8.     cur_sum += a[i]
  9.     if cur_sum <= s:
  10.         first_answ = i + 1
  11.     else:
  12.         cur_sum -= a[i]
  13.         break
  14. print(first_answ)
  15. cur_sum -= a[first_answ - 1]
  16. for i in range(n - 1, -1, -1):
  17.     if cur_sum + a[i] <= s:
  18.         print(a[i])
  19.         break
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement