pythondef solve(N, K, AS):
left = 0 # (3)
right = max(AS) # (4)
while left < right - 1:
x = (left + right) // 2
y = f(x) # (1)
if y > K: # (2)
left = x
else:
right = x
return right