알고리즘 문제풀이

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

wiojfe 2024. 5. 12. 18:20

https://www.acmicpc.net/problem/11497

 

 

맨 첫 번째 통나무와 마지막 통나무도 인접해 있다고 봐야 하기 때문에 무조건 통나무 높이에 따른 정렬을 하면 안 된다. 

2칸씩 떨어진 통나무들의 높이를 비교해야 한다. 

t =int(input())

for _ in range(t):
    n = int(input())
    arr =list(map(int, input().split()))
    arr.sort()
    ans = 0 
    for i in range(2,n):
        ans=max(ans,arr[i]-arr[i-2])
    print(ans)