https://www.acmicpc.net/problem/1874
current = 1부터 시작해, 수열의 현재 숫자보다 작거나 같을 때까지 계속 push.
push할 때마다 + 저장.
목표 숫자와 같아지면 pop하고 - 저장.
스택의 top이 수열 숫자보다 크면 불가능하므로 "NO" 출력.
n = int(input())
target = [int(input()) for _ in range(n)]
stack = []
result = []
current = 1
isPossible = True
for num in target:
# num까지 push하면서 스택 채우기
while current <= num:
stack.append(current)
result.append('+')
current += 1
# top이 num과 같으면 pop
if stack[-1] == num:
stack.pop()
result.append('-')
else:
# 스택 top이 num보다 크면 더 이상 만들 수 없음
isPossible = False
break
if isPossible:
for r in result:
print(r)
else:
print('NO')
현재 push해야 할 숫자: current
실제 스택을 시뮬레이션할 리스트: stack
연산 기록을 담을 리스트: result
가능 여부 체크용: isPossible
필요한 리스트와 변수들이 직관적으로 떠오르지 않았고 for문 순회 기준을 무엇으로 잡아야할지 몰라서 풀이를 찾는데 오래걸렸다...ㅠ