흙금이네 블로그

[BOJ] 1263 - 시간 관리 (Python) 본문

알고리즘

[BOJ] 1263 - 시간 관리 (Python)

흙금 2023. 4. 18. 11:56

 

 

아이디어

 

마감 시간 기준으로 정렬한 후 소요되는 시간을 빼면서 이전 마감 시간과 비교한다.

 

 

풀이

 

import sys

input = sys.stdin.readline

def solution():
    N = int(input())
    works = [tuple(map(int, input().split())) for _ in range(N)]
    works.sort(key=lambda x: -x[1])
    res = works[0][1]-works[0][0]
    for i in range(1, N):
        if res > works[i][1]:
            res = works[i][1]
        res -= works[i][0]
    print(res if res >= 0 else -1)

solution()

 

Comments