Created
June 6, 2022 15:02
-
-
Save mym0404/b5f15555cb8b1de12e83d6a0c5ba8c55 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 ** 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