💡문제접근
- 이전 포스팅에 있었던 [[백준] 2467번 용액]과의 차이라면 정렬의 유무이다.
오름차순 정렬만 해준다면 쉽게 해결할 수 있다.
💡코드(메모리 : 42172KB, 시간 : 128ms)
import sys
input = sys.stdin.readline
N = int(input())
solution = list(map(int, input().strip().split()))
solution.sort()
p1 = 0
p2 = len(solution) - 1
Min = sys.maxsize
while True:
if p1 >= p2:
break
if abs(solution[p1] + solution[p2]) < Min:
Min = abs(solution[p1] + solution[p2])
a = solution[p1]
b = solution[p2]
if solution[p1] + solution[p2] > 0:
p2 -= 1
elif solution[p1] + solution[p2] < 0:
p1 += 1
else:
break
print(a, b)
💡소요시간 : 10m