Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #f = open('tst.txt')
- f = open('26.txt')
- s, n = map(int, f.readline().split())
- print(n,s)
- a = [int(i) for i in f.readlines()]
- f.close()
- #print(a)
- print(len(a))
- n = len(a)
- pf = [0] * n
- a = sorted(a)
- print(a)
- pf[0] = a[0]
- for i in range(1, n):
- pf[i] = pf[i-1] + a[i]
- #for i in range(n):
- # print(i, a[i], pf[i])
- k = 0
- for i in range(n):
- if pf[i] > s:
- k = i - 2
- break
- print("k = ", k)
- print(pf[k])
- tot = pf[k]
- mx = a[k + 1]
- for i in range(n - 1, 0, -1):
- if a[i] + pf[k] <= s:
- tot += a[i]
- mx = a[i]
- break
- print(k + 2, mx)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement