nq1s788

Сплоченная команда

Oct 11th, 2025
211
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.29 KB | None | 0 0
  1. n = int(input())
  2. a = sorted([int(input()) for i in range(n)])
  3. l = 0
  4. r = 0
  5. s = a[0]
  6. answ = a[0]
  7. while r + 1 < n:
  8.     if r - l < 1 or a[l] + a[l + 1] >= a[r + 1]:
  9.         s += a[r + 1]
  10.         r += 1
  11.         answ = max(answ, s)
  12.     else:
  13.         s -= a[l]
  14.         l += 1
  15. print(answ)
Advertisement
Add Comment
Please, Sign In to add comment