BOJ - 2473 - 세 용액
Updated:
import sys
def solution():
N = int(sys.stdin.readline())
arr = list(map(int, sys.stdin.readline().split()))
arr.sort()
_INF = 1e11
ret = [0] * 3
for i in range(N-2):
if i > 0 and arr[i] == arr[i-1]: continue
left = i + 1
right = N -1
while left < right:
temp = arr[i] + arr[left] + arr[right]
if abs(temp) < abs(_INF):
ret[0] = arr[i]
ret[1] = arr[left]
ret[2] = arr[right]
_INF = temp
if temp < 0: left += 1
elif temp > 0: right -= 1
else:
print(arr[i], arr[left], arr[right])
return
for k in range(3): print(ret[k], end=' ')
solution()
https://www.acmicpc.net/problem/2473
Leave a comment