알고리즘 문제풀이

풍선 맞추기 [백준 11509]

wiojfe 2025. 3. 13. 14:13

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

 

import sys

input = sys.stdin.readline
n = int(input())
balloons = list(map(int, input().split()))

arrows = {}
arrow_count = 0
for height in balloons:
    if height in arrows and arrows[height] > 0:
        arrows[height] -= 1
        arrows[height - 1] = arrows.get(height - 1, 0) + 1
    else:
        arrow_count += 1
        arrows[height - 1] = arrows.get(height - 1, 0) + 1

print(arrow_count)