알고리즘

<백준> 2470번 파이썬 알고리즘 [투포인터]

changha. 2022. 4. 17. 22:19
import sys

n = int(input())
arr = list(map(int, input().split(' ')))
start = 0
end = n - 1 
arr.sort()
res = sys.maxsize
final = []
while start < end:
    total = arr[start] + arr[end]
    
    if abs(total) < res:
        res = abs(total)
        final = [arr[start], arr[end]]
    
    if total < 0:
        start += 1
    else:
        end -= 1
    
    
print(final[0], final[1])