[백준 11497, Python] 통나무 건너뛰기

나무에물주기·2022년 10월 21일
0

Coding Test

목록 보기
11/77
# 백준 11497 통나무 건너뛰기

import sys
input = sys.stdin.readline

n = int(input()) # 테스트 케이스 입력
for i in range(n): # n번 반복
    a = int(input()) # 통나무의 개수 입력
    tree = list(map(int,input().split())) # 통나무의 높이를 리스트 형태로 입력
    tree.sort() # tree를 오름차순 정렬
    res = 0 # 결과값을 출력할 변수 생성
    for j in range(2, a): # 2 ~ a까지 반복
        res = max(res, abs(tree[j] - tree[j - 2])) # 높이차가 2씩 나도록 한 배열중 최댓값을 res에 대입
    print(res) # res출력
profile
개인 공부를 정리함니다

0개의 댓글