문제 링크
https://www.acmicpc.net/problem/6549
import sys
sys.setrecursionlimit(10000)
def findArea(heights):
if len(heights) == 0:
return 0
width = len(heights)
minHeight = min(heights)
minIndex = heights.index(minHeight)
return max(findArea(heights[:minIndex]), findArea(heights[minIndex+1:]), minHeight * width)
while True:
hist = list(map(int, input().split()))
n = hist[0]
heights = hist[1:]
if n == 0 :
break
print(findArea(heights))
import sys
input = sys.stdin.readline
def maxSize():
max_size = 0
stack = []
for i in range(n):
left = i
while stack and stack[-1][0] >= heights[i]:
h, left = stack.pop()
tmp_size = h * (i - left)
max_size = max(max_size, tmp_size)
stack.append([heights[i],left])
for h, point in stack:
max_size = max(max_size, (n-point)*h)
return max_size
while True:
n, *heights = map(int, input().split())
if n == 0:
break
print(maxSize())