299. 같이 눈사람 만들래?

아현·2021년 9월 9일
0

Algorithm

목록 보기
313/400

백준




1. 투포인터



import sys
input = sys.stdin.readline
n = int(input())
snow = list(map(int, input().split()))
snow.sort()

answer = sys.maxsize

for i in range(n):
        for j in range(i + 3, n):
            left, right = i + 1, j - 1
            while left < right:
                tmp = (snow[i] + snow[j]) - (snow[left] + snow[right])
                if abs(answer) > abs(tmp):
                    answer = abs(tmp)

                if tmp < 0: 
                    right -= 1
                else: 
                    left += 1

print(answer)



profile
Studying Computer Science

0개의 댓글