스택을 활용함
import sys
def solution(data):
arr = data[1:]
stack = []
my_max = 0
for idx, value in enumerate(arr):
my_idx = idx
while stack and stack[-1][0] >= value:
h, my_idx = stack.pop()
my_max = max(my_max, (idx - my_idx) * h)
stack.append((value, my_idx))
for h, idx in stack:
my_max = max(my_max, (n - idx) * h)
print(my_max)
while True:
data = list(map(int, sys.stdin.readline().split()))
n = data[0]
if n == 0:
break
solution(data)
'파이썬 코테 준비' 카테고리의 다른 글
[백준 20040] 사이클 게임 - Python(파이썬) (0) | 2021.03.21 |
---|---|
[백준 1717] 집합의 표현 - Python(파이썬) (0) | 2021.03.11 |
[백준 11657] 타임머신 - Python(파이썬) (0) | 2021.03.11 |
[백준 9370] 미확인 도착지 - Python(파이썬) (0) | 2021.03.11 |
[백준 1504] 특정한 최단 경로 - Python(파이썬) (0) | 2021.03.11 |
댓글