백준 1874 python 실버2

인지용·2026년 1월 8일

알고리즘

목록 보기
49/50

https://www.acmicpc.net/problem/1874


import sys

def input():
    return sys.stdin.readline().strip()

n = int(input())
target = [int(input()) for _ in range(n)]
stack = []
result = []
cur = 1

for next in target: 

    while cur <= next:
        stack.append(cur)
        result.append("+")
        cur += 1

    if stack and stack[-1] == next:
        stack.pop()
        result.append("-")
    else:
        print("NO")
        sys.exit(0)

print("\n".join(result))
profile
한-줄

0개의 댓글