BOJ - 1725 - 히스토그램

Updated:

import sys

def solution():
    N = int(input())
    arr = []
    for _ in range(N):
        arr.append(int(sys.stdin.readline()))

    arr.append(0)
    arr.insert(0, 0)
    check = [0]
    square = 0

    for i in range(1, N+2):
        while check and (arr[check[-1]] > arr[i]):

            h = check.pop()
            square = max(square, (i - 1 - check[-1]) * arr[h])
        check.append(i)
    print(square)
solution()

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

Categories:

Updated:

Leave a comment