BOJ - 2470 - 두 용액

Updated:

import sys

def solution():
    N = int(sys.stdin.readline())
    arr = list(map(int, sys.stdin.readline().split()))
    arr.sort()

    left = 0
    right = N-1
    tLeft = 0
    tRight = N-1
    ret = arr[left] + arr[right]
    while left < right:
        temp = arr[left] + arr[right]
        if abs(temp) < abs(ret):
            ret = temp
            tLeft = left
            tRight = right
            if ret == 0: break

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

    print(arr[tLeft], arr[tRight])

solution()

https://www.acmicpc.net/problem/2470

Categories:

Updated:

Leave a comment