앎을 경계하기

Programming/Algorithm

백준 #10773 - 제로 python

양갱맨 2019. 10. 19. 01:29

image

K = int(input())
stack = []
for k in range(K):
    num = int(input())
    if num == 0:
        del stack[-1]
    else:
        stack.append(num)

print(sum(stack))