Algorithm/boj

[파이썬] 1863 스카이라인 쉬운거

takeU 2022. 7. 22. 15:26
반응형
import sys
input = sys.stdin.readline

n = int(input())
stack, ans = [], 0

for _ in range(n):
    x, y = map(int, input().split())
    while stack and stack[-1] > y:
        ans += 1
        stack.pop()
    if stack and stack[-1] == y:
        continue
    stack.append(y)

while stack:
    if stack[-1] > 0:
        ans += 1
    stack.pop()

print(ans)

스택