Created
June 6, 2022 14:57
-
-
Save mym0404/f37c9ae32a8b01717a0b7d103e3104a9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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