백준 1027 고층건물

이승주·2024년 7월 30일

알고리즘

목록 보기
2/2
post-thumbnail

def count_left(now):
min = float('inf')
cnt = 0
for idx in range(now-1, -1, -1):
inc = (buildings[now] - buildings[idx]) / (now - idx)
if min > inc:
min = inc
cnt += 1
return cnt

def count_right(now):
max = -float('inf')
cnt = 0
for idx in range(now+1, N):
inc = (buildings[now] - buildings[idx]) / (now - idx)
if max < inc:
max = inc
cnt += 1
return cnt

N = int(input())
buildings = list(map(int, input().split()))
ret = 0
for i in range(N):
left = count_left(i)
right = count_right(i)
ret = max(ret, left + right)

print(ret)

profile
개발자 공부

0개의 댓글