티스토리 뷰
728x90
코드
T = 10
for tc in range(1, T+1):
N = int(input())
b_lst = list(map(int, input().split())) # 빌딩리스트
# 변수초기화
cnt = 0
# 앞 뒤 0 두개 뺀 상태에서 for 문 돌면서
for i in range(2, N-2):
# 왼쪽 2개보다 크고 & 오른쪽 두개보다 크면
if b_lst[i] > b_lst[i-1] and b_lst[i] > b_lst[i-2] and b_lst[i] > b_lst[i+1] and b_lst[i] > b_lst[i+2]:
# 양 옆 애들 중 높이 가장 높은 애 만큼 빼주고 카운팅 해줌
# 값 차이가 가장 적은 애가 높이가 가장 높기 때문에 반복문 돌려서 두번째로 높은애 찾음
a1 = b_lst[i] - b_lst[i - 2]
a2 = b_lst[i] - b_lst[i - 1]
a3 = b_lst[i] - b_lst[i + 1]
a4 = b_lst[i] - b_lst[i + 2]
min_gap = a1
for a in [a1, a2, a3, a4]:
if a < min_gap:
min_gap = a
cnt += min_gap
print("#{} {}".format(tc, cnt))
'algorithm > swea' 카테고리의 다른 글
[swea] 1222. 계산기1 / python 파이썬 (0) | 2021.04.09 |
---|---|
[swea] 4866. 괄호검사 / python 파이썬 (0) | 2021.04.09 |
[swea] 1208. Flatten / python 파이썬 (0) | 2021.04.09 |
[swea] 4408. 자기 방으로 돌아가기 / python 파이썬 (0) | 2021.04.09 |
[swea] 4861. 회문 / python 파이썬 (0) | 2021.04.09 |
댓글
글 보관함
TAG
- dfs
- Python
- 삼성코테
- 17406 배열돌리기4
- react
- 2579 계단오르기
- 알고리즘
- 21609 상어 중학교
- 백준
- 20056 마법사 상어와 파이어볼
- 영어끝말잇기
- BFS
- 삼성기출
- merge 에러
- 기지국설치
- 파이썬
- swea
- merge에러
- 2018 카카오 공채
- 20057 마법사 상어와 토네이도
- 보석쇼핑
- 프로그래머스
- 브루트포스
- dp
- git 미러링
최근에 올라온 글
- Total
- Today
- Yesterday
최근에 달린 댓글