def check(buildings, idx):
l = idx - 2 if idx >= 2 else 0
r = idx + 3
sides = buildings[l : idx] + buildings[idx + 1 : r]
side_max = max(sides)
height = buildings[idx]
if height - side_max > 0:
return height - side_max
else:
return 0
T = 10
for t in range(1, T + 1):
n = int(input().strip())
buildings = list(map(int, input().split()))
total = 0
for idx in range(n):
total += check(buildings, idx)
print(f'#{t} {total}')
'알고리즘 문제 풀이 > SWEA' 카테고리의 다른 글
[SWEA 1974 python] 스도쿠 검증 (0) | 2021.08.16 |
---|---|
[SWEA 4408 python] 자기 방으로 돌아가기 (0) | 2021.08.16 |
[SWEA 10804 python] 문자열의 거울상 (0) | 2021.08.13 |
[SWEA 1979 python] 어디에 단어가 들어갈 수 있을까 (0) | 2021.08.13 |
[SWEA 1966 python] 숫자를 정렬하자 (0) | 2021.08.13 |