백준 1826 - 연료 채우기


백준 1826 - 연료 채우기

1234567891011121314151617181920212223242526import sys, heapq n = int(sys.stdin.readline())q = [] for _ in range(n): a,b = map(int, sys.stdin.readline().split()) heapq.heappush(q,[a,b])target, fuel = map(int, sys.stdin.readline().split()) cnt = 0bucket = []while fuel < target: while q and q[0][0] <= fuel: tmp = heapq.heappop(q) heapq.heappush(bucket, [-tmp[1], tmp[0]]) if not bucket: cnt = -1 break tmp = heapq.heappop(bucket) fuel -= tmp[0] cnt += 1 print(cnt)Colored by Color Scriptercs 보유하고 있는 연료가 목적지 보다 적을 때 현재 보유하고 있는 연료로 갈 수 있는 거리 범위의 거리와 연료를..........



원문링크 : 백준 1826 - 연료 채우기