문제로 가기
import sys
input = sys.stdin.readline
c_tree, target = list(map(int, list(input().split())))
trees = list(map(int, list(input().split())))
trees.sort(reverse=True)
def check(cutHeight):
result = 0
for i in trees:
if i > cutHeight:
result += i - cutHeight
if target <= result:
return True
else:
break
return False
start = 0
end = trees[0]
def search(start, end):
if end <= start:
return start
if (start + end )//2 == (start+ end)/2:
mid = (start + end )//2
else:
mid = (start+ end) //2 + 1
if check(mid):
start = mid
else:
end = mid - 1
return search(start, end)
print(search(start, end))
reversion
def search():
start, end = 0, trees[0]
ans = 0
while start <= end:
mid = (start + end) // 2
if check(mid):
ans = mid
start = mid + 1
else:
end = mid - 1
return ans