적어도 M만큼의 떡을 가져가기위해 설정할 수 있는 최대 높이를 구하는 문제
n, m = map(int, input().split())
height = list(map(int, input().split()))
height.sort(reverse=True)
end = height[0]
start = 0
mx = -1
while start <= end:
inspection = (start + end) // 2
sm = 0
for h in height:
if h > inspection:
sm += (h - inspection)
if sm >= m:
start = inspection + 1
mx = max(mx, inspection)
elif sm < m:
end = inspection - 1
print(mx)
이진 탐색
-> 새로운 start와 end 설정 시 +1, -1을 해줘야 한다. 또한 이진 탐색의 종료조건은 start <= end