I am trying to solve this problem: https://www.spoj.com/problems/EKO/
i think I have optimal binary search solution but running into TLE 
Here is my code:
'''
https://www.spoj.com/problems/EKO/
'''
def chopped_off(heights, t):
return sum(max(i-t, 0) for i in heights)
def search_optimal_height(heights, threshold):
lo = min(heights) - threshold
hi = max(heights)
while lo <= hi:
mid = (hi + lo)//2
if chopped_off(heights, mid) >= threshold:
lo = mid+1
else:
hi = mid - 1
return hi
n, m = map(int, raw_input().split())
heights = [int(i) for i in raw_input().split()]
ans = search_optimal_height(heights, m)
print ans
Please help! 