Advertisement
Korotkodul

dem22.n26

Jun 18th, 2023 (edited)
773
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.62 KB | None | 0 0
  1. #f = open('tst.txt')
  2. f = open('26.txt')
  3. s, n = map(int, f.readline().split())
  4. print(n,s)
  5. a = [int(i) for i in f.readlines()]
  6. f.close()
  7.  
  8. #print(a)
  9. print(len(a))
  10.  
  11. n = len(a)
  12. pf = [0] * n
  13. a = sorted(a)
  14.  
  15. print(a)
  16.  
  17. pf[0] = a[0]
  18. for i in range(1, n):
  19.     pf[i] = pf[i-1] + a[i]
  20.  
  21.  
  22. #for i in range(n):
  23. #    print(i, a[i], pf[i])
  24.    
  25.    
  26. k = 0
  27.  
  28.  
  29. for i in range(n):
  30.     if pf[i] > s:
  31.         k = i - 2
  32.         break
  33.  
  34. print("k = ", k)
  35. print(pf[k])
  36.    
  37. tot = pf[k]
  38. mx = a[k + 1]
  39. for i in range(n - 1, 0, -1):
  40.     if a[i] + pf[k] <= s:
  41.         tot += a[i]
  42.         mx = a[i]
  43.         break
  44. print(k + 2, mx)
  45.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement