[힙] 1826번 연료 채우기

정은경·2020년 7월 4일
0

백준 문제풀이

목록 보기
26/51

1. 문제


2. 나의 풀이

아직 안돌아가는 나의 풀이

import sys
import heapq
from queue import PriorityQueue

gas_station = []
pq = PriorityQueue()

N = int(input())
for _ in range(N):
    distance, fuel = [int(x) for x in sys.stdin.readline().split()]
    gas_station.append((distance, fuel))
gas_station.sort(key=lambda item: item[0])

End, oil = [int(x) for x in sys.stdin.readline().split()]
ans, here = 0, 0

for i in range(len(gas_station)):
    print(i)
    while pq and (here + oil) < gas_station[i][0]:
        oil += pq.get()[1]
        ans += 1
    oil = oil - (gas_station[i][0]-here)

    if oil < 0:
        break

while pq and here + oil < End:
    oil += pq.get()[1]
    ans += 1

print(ans) if here + oil >= End else print(-1)

3. 남의 풀이

4. 느낀 점

profile
#의식의흐름 #순간순간 #생각의스냅샷

0개의 댓글