def slope(x1, y1, x2, y2):
return (y2 - y1) / (x2 - x1)
N = int(input())
heights = list(map(int, input().split()))
maxViewCount = 0
for i in range(N):
viewCount = 0
maxSlopeRight = -float('inf') // 음의 무한대로 초기화
for j in range(i+1, N):
slopeRight = slope(i, heights[i], j, heights[j])
if maxSlopeRight < slopeRight:
maxSlopeRight = slopeRight
viewCount += 1
minSlopeLeft = float('inf') // 양의 무한대로 초기화
for j in range(i-1, -1, -1):
slopeLeft = slope(i, heights[i], j, heights[j])
if slopeLeft < minSlopeLeft :
minSlopeLeft = slopeLeft
viewCount += 1
maxViewCount = max(maxViewCount, viewCount)
첫 번째 빌딩부터 마지막 빌딩까지 순회하면서 해당 빌딩에 위치했을 때 보이는 빌딩의 수를 계산하기 위해 viewCount 변수를 0으로 초기화 시킨다.
현재 위치한 빌딩을 기준으로 오른쪽부터 순차적으로 탐색한다.