Advertisement
serega1112

Bliny

Jan 23rd, 2022
879
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. n = int(input())
  2. nums = []
  3. for _ in range(n):
  4.     nums.append(int(input()))
  5.  
  6. l = 0
  7. r = nums[-1]
  8.  
  9. def check(t, nums):
  10.     extra = 0
  11.     i = len(nums) - 1
  12.     while i >= 0 and nums[i] > t:
  13.         extra += nums[i] - t
  14.         i -= 1
  15.     return extra <= t
  16.  
  17. while r - l > 1:
  18.     mid = l + (r - l) // 2
  19.     if check(mid, nums):
  20.         r = mid
  21.     else:
  22.         l = mid
  23.  
  24. print(r)
  25.  
Advertisement
Advertisement
Advertisement
RAW Paste Data Copied
Advertisement