백준 2470 - 두 용액 (파이썬)

Updated:

Answer

n = int(input())
a = sorted(list(map(int, input().split())))

left = 0
right = n - 1
candidate = []
total = float('inf')

while left < right:
    tmp = a[left] + a[right]

    if total > abs(tmp):
        total = abs(tmp) 
        candidate = [a[left], a[right]]

        if total == 0:
            break
    
    if tmp > 0:
        right -= 1
    else:
        left += 1

print(candidate[0], candidate[1])

Categories:

Updated: