https://www.acmicpc.net/problem/1826
import heapq
import sys
# input = sys.stdin.read
# data = input().splitlines()
N = int(input()) # 주유소 개수
stations = []
for i in range(1, N + 1):
# a, b = map(int, data[i].split())
a, b = map(int, input().split())
stations.append((a, b))
L, P = map(int, input().split()) # 마을까지 거리, 현재 연료
stations.sort()
max_heap = []
fuel = P
count = 0
index = 0
while fuel < L:
while index < N and stations[index][0] <= fuel:
heapq.heappush(max_heap, -stations[index][1])
index += 1
if not max_heap:
print(-1)
exit()
fuel += -heapq.heappop(max_heap)
count += 1 # 주유 횟수 증가
print(count)
'알고리즘 문제풀이' 카테고리의 다른 글
House Prices Going Up [백준 25778] (0) | 2025.03.30 |
---|---|
풍선 맞추기 [백준 11509] (0) | 2025.03.13 |
파일 합치기3 [백준 13975] (0) | 2025.03.09 |
멀티탭 스케줄링 [백준 1700] (0) | 2025.03.08 |
흙길 보수하기 [백준 1911] (0) | 2025.03.08 |