Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- n = int(input())
- a = sorted([int(input()) for i in range(n)])
- l = 0
- r = 0
- s = a[0]
- answ = a[0]
- while r + 1 < n:
- if r - l < 1 or a[l] + a[l + 1] >= a[r + 1]:
- s += a[r + 1]
- r += 1
- answ = max(answ, s)
- else:
- s -= a[l]
- l += 1
- print(answ)
Advertisement
Add Comment
Please, Sign In to add comment