https://leetcode.com/problems/furthest-building-you-can-reach/description/
import heapq
class Solution:
def furthestBuilding(self, heights: List[int], bricks: int, ladders: int) -> int:
heap = []
n = len(heights)
for i in range(1, n):
jump = heights[i] - heights[i-1]
if jump > 0:
heapq.heappush(heap, jump)
if len(heap) > ladders:
bricks -= heapq.heappop(heap)
if bricks < 0:
return i-1
return n-1