two-pointer
import sys
input=sys.stdin.readline
N=int(input())
arr=list(map(int,input().split()))
answer=2000000000
left,right=0,N-1 # 양끝에서 출발
result=[]
while left<right:
compare=arr[left]+arr[right]
if abs(compare)<answer:
answer=abs(compare)
result=[arr[left],arr[right]]
if compare<0: left+=1 # 더한합이 음수면 오른쪽으로 이동
else: right-=1 # 더한합이 양수면 왼쪽으로 이동
print(result[0],result[1])
'IT > coding study' 카테고리의 다른 글
[acmicpc] 1806. 부분합(python) (2) | 2022.09.21 |
---|---|
[acmicpc] 1987. 알파벳(python) (0) | 2022.09.19 |
[acmicpc] 20922. 겹치는 건 싫어(python) (0) | 2022.09.18 |
[acmicpc] 3758. KCPC(python) (0) | 2022.09.18 |
[SWEA] 2383. 점심 식사시간(python) (0) | 2022.09.16 |