백준 1263번: 시간 관리 #Python

ColorlessDia·2025년 6월 23일

algorithm/baekjoon

목록 보기
582/809
import sys
from heapq import heappush, heappop

input = sys.stdin.readline

N = int(input())

schedule_list = []

for _ in range(N):
    T, S = map(int, input().split())

    heappush(schedule_list, (-S, -T))

time = 1000000

while schedule_list:
    S, T = map(lambda x: -x, heappop(schedule_list))

    if S <= time:
        time = S - T
    else:
        time -= T

if 0 <= time:
    print(time)
else:
    print(-1)

0개의 댓글