백준 Algorithm
[백준 2056 작업 문제] PYTHON
harry595
2021. 8. 17. 16:57
이번 문제의 핵심은 K번 작업을 시작하기 전 완료되야하는 작업들이 1~K-1라는 부분이다.
따라서 for문을 돌며 K번째 작업은 1~K-1 작업 시간의 max 값 + K번째 작업의 시간이 된다.
이를 코드로 구현하면 아래와 같다.
T = int(input())
Clist = {}
cost = {0: 0}
for i in range(1, T+1):
tmp = list(map(int, input().split()))
cost[i] = tmp[0]
if(len(tmp) == 2):
Clist[i] = [0]
else:
Clist[i] = tmp[2:]
for j in range(1, T+1):
temp = 0
for k in Clist[j]:
temp = max(temp, cost[k])
cost[j] += temp
print(max(cost.values()))