Advertisement
nq1s788

26 жадник 2

Dec 21st, 2024
25
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.42 KB | None | 0 0
  1. #https://inf-ege.sdamgia.ru/problem?id=27423
  2. data = open('26_demo.txt').readlines()
  3. s, n = map(int, data[0].split())
  4. a = list(map(int, data[1:]))
  5. a.sort()
  6. cur_s = 0
  7. cnt = 0
  8. for i in range(n):
  9.     if a[i] + cur_s <= s:
  10.         cur_s += a[i]
  11.         cnt += 1
  12. print(cnt, end=' ')
  13. cur_s -= a[cnt - 1] #вычли последний
  14. answ = 0
  15. for i in range(cnt, n):
  16.     if cur_s + a[i] <= s:
  17.         answ = a[i]
  18. print(answ)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement