Skip to content

Instantly share code, notes, and snippets.

@mym0404
Created June 6, 2022 14:57
Show Gist options
  • Save mym0404/f37c9ae32a8b01717a0b7d103e3104a9 to your computer and use it in GitHub Desktop.
Save mym0404/f37c9ae32a8b01717a0b7d103e3104a9 to your computer and use it in GitHub Desktop.
n = int(input())
arr = list(map(int, input().split()))
m = int(input())
# 그냥 모두 줄 수 있는 지 검사
S = sum(arr)
if m >= S:
print(max(arr))
exit(0)
# 모두 줄 수 없다면 이분탐색
left, right = 0, 10 ** 9
answer = -1
while left <= right:
mid = (left + right) // 2
need = 0
for i in range(n):
need += arr[i] if arr[i] <= mid else mid
if need <= m:
answer = mid
left = mid + 1
else:
right = mid - 1
print(answer)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment