https://www.acmicpc.net/problem/1931
1931번: 회의실 배정
(1,4), (5,7), (8,11), (12,14) 를 이용할 수 있다.
www.acmicpc.net
- 회의실의 정렬을 어떻게 해야되는지 처음에 이해하지 못 했었다.
- 처음에는 끝나는 시간 - 시작 시간으로 cost를 구해서 정렬하였다.
- 하지만, '빨리 끝날 수록 뒤에서 고려해 볼 기회가 많다' 라는 힌트를 구글링을 통해 찾았고,
- 끝나는 시간이 같으면 시작 시간을 기준으로 정렬하도록 하였다.
더보기
import sys
input = sys.stdin.readline
# input
N = int(input())
startEndList = []
for ndx in range(N):
startEnd = list(map(int, str(input()).split()))
startEndList.append(startEnd)
'''
빨리 끝나는 회의 순서대로 정렬을 해야한다.
빨리 끝날수록 뒤에서 고려해볼 기회가 많다.
'''
startEndList.sort(key= lambda x: (x[1], x[0]))
# calc
answer = 1
lastEndTime = startEndList[0][1]
for idx, startEndTime in enumerate(startEndList):
if 0 == idx: continue
if startEndTime[0] >= lastEndTime:
answer += 1
lastEndTime = startEndTime[1]
# print
print(answer)
'Coding Problem > 백준' 카테고리의 다른 글
[백준] 1037 - 약수 (0) | 2021.05.31 |
---|---|
[백준] 1010 - 다리놓기 (0) | 2021.05.31 |
[백준] 13305 - 주유소 (0) | 2021.05.28 |
[백준] 1541 - 잃어버린 괄호 (0) | 2021.05.28 |
[백준] 11047 - 동전 0 (0) | 2021.05.28 |