본문 바로가기
알고리즘/백준

백준-10773번(제로)-python3

by nyeongha 2023. 11. 30.
import sys
arr=[]
for x in range(int(sys.stdin.readline())):
    a=int(sys.stdin.readline())
    if a==0:
        if arr:
            arr.pop()
    else:
        arr.append(a)
print(sum(arr))