백준 Python 12789 도키도키 간식드리미

Seohyun·2023년 8월 5일
0

알고리즘

목록 보기
16/36

문제 링크

  • 큐와 스택을 함께 사용하였다.
from collections import deque

n = int(input())

line = deque(map(int, input().split()))

wait = []

turn = 1

while line:
    
    if line[0] == turn:
        line.popleft()
        turn += 1
    else:
        wait.append(line.popleft())
        
    while wait and wait[-1] == turn:
        wait.pop()
        turn += 1
        
if wait:
    print("Sad")
else:
    print("Nice")
profile
Hail hamster

0개의 댓글