Caso # | Resultado | Tiempo | Memoria |
---|---|---|---|
#1 |
Correcto
|
0.012 s | 3 KBi |
#2 |
Correcto
|
0.011 s | 3 KBi |
#3 |
Correcto
|
0.013 s | 3 KBi |
#4 |
Correcto
|
0.01 s | 3 KBi |
#5 |
Correcto
|
0.012 s | 3 KBi |
#6 |
Correcto
|
0.012 s | 3 KBi |
#7 |
Correcto
|
0.01 s | 3 KBi |
#8 |
Correcto
|
0.012 s | 3 KBi |
#9 |
Correcto
|
0.012 s | 3 KBi |
#10 |
Correcto
|
0.008 s | 3 KBi |
#11 |
Correcto
|
0.01 s | 3 KBi |
#12 |
Correcto
|
0.013 s | 3 KBi |
#13 |
Correcto
|
0.012 s | 3 KBi |
#14 |
Correcto
|
0.009 s | 3 KBi |
#15 |
Correcto
|
0.011 s | 3 KBi |
#16 |
Correcto
|
0.013 s | 3 KBi |
#17 |
Correcto
|
0.009 s | 3 KBi |
#18 |
Correcto
|
0.012 s | 3 KBi |
#19 |
Correcto
|
0.009 s | 3 KBi |
def maxima_area_valla(alturas): stack = [] max_area = 0 for i, altura in enumerate(alturas): while stack and altura < alturas[stack[-1]]: height = alturas[stack.pop()] width = i if not stack else i - stack[-1] - 1 max_area = max(max_area, height * width) stack.append(i) while stack: height = alturas[stack.pop()] width = len(alturas) if not stack else len(alturas) - stack[-1] - 1 max_area = max(max_area, height * width) return max_area def main(): # Leer el número de edificios (Read the number of buildings) n = int(input()) # Leer las alturas de los edificios (Read the heights of the buildings) alturas = list(map(int, input().split())) # Calcular la máxima área posible para la valla (Calculate the maximum possible area for the fence) max_area = maxima_area_valla(alturas) # Imprimir el resultado (Print the result) print(max_area) if __name__ == "__main__": main()