Skip to content

Instantly share code, notes, and snippets.

@mym0404
Created June 6, 2022 15:02
Show Gist options
  • Save mym0404/b5f15555cb8b1de12e83d6a0c5ba8c55 to your computer and use it in GitHub Desktop.
Save mym0404/b5f15555cb8b1de12e83d6a0c5ba8c55 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 ** 5
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