Advertisement
nq1s788

26 жадник

Dec 18th, 2024 (edited)
38
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.49 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. if sum(a) <= s:
  6.     print(n, max(a))
  7.     exit(0)
  8. a.sort()
  9. cur_s = 0
  10. cnt = 0
  11. while cur_s <= s:
  12.     cur_s += a[cnt]
  13.     cnt += 1
  14. #cnt -= 1
  15. print(cnt, end=' ')
  16. #cur_s -= a[cnt] #вычли лишний
  17. cur_s -= a[cnt - 1] #вычли последний
  18. for i in range(cnt, n):
  19.     if cur_s + a[i] > s:
  20.         print(a[i - 1])
  21.         break
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement