[알고리즘/백준] 2470번 : 두 용액(python)

유현민·2022년 7월 20일
0

알고리즘

목록 보기
222/253

투 포인터 문제이다.
두 용액의 합을 절대값으로 바꾸고 비교하면 된다.

import sys

input = sys.stdin.readline
N = int(input())
a = sorted(list(map(int, input().split())))
s = 0
e = N - 1
tmp = 2e9
ans = list()
while s < e:
    tot = a[s] + a[e]
    if abs(tot) < tmp:
        tmp = abs(tot)
        ans = [a[s], a[e]]

    if tot < 0:
        s += 1
    else:
        e -= 1
print(*ans)
profile
smilegate megaport infra

0개의 댓글