프로그래밍/삼성 SWEA

[SWEA][Python3] 3503. 초보자를 위한 점프대 배치하기

snoopybox 2019. 5. 30. 00:18

나의 풀이 :

T = int(input())
for tc in range(1, T + 1):
n = int(input())
jumps = sorted(map(int, input().split()))
ans = 0
for i in range(n-2):
ans = max(ans, jumps[i+2]-jumps[i])
print('#{} {}'.format(tc, ans))


한마디 :

원형으로 배치하기 때문에 정렬해서 가장 작은 점프대를 먼저 놓고, 좌우로 1개씩 번갈아 놓으면 된다.