BOJ - 6549 - 히스토그램에서 가장 큰 직사각형

Updated:

import sys

def solution():

    while True:
        arr = list(map(int, sys.stdin.readline().split()))
        if (arr[0] == 0): return
        
        N = arr[0]
        arr = arr[1:]
        
        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/6549

Categories:

Updated:

Leave a comment