알고리즘
[백준] 17952번 과제는 끝나지 않아! python
_Myway
2023. 6. 1. 23:03
자꾸 시간초과가 나서 readline 추가
import sys
input = sys.stdin.readline
n = int(input())
hw = []
final_score = 0
idx = 0
for _ in range(n):
line = list(map(int,input().split()))
if line[0]==1:
if line[2]-1==0:
final_score += line[1]
else:
hw.append([line[1],line[2]-1])
idx += 1
else:
if len(hw)>0:
hw[idx-1][1] -= 1
if hw[idx-1][1]==0:
score, time = hw.pop()
final_score+=score
idx -= 1
print(final_score)