Skip to content

Commit f7259b3

Browse files
committed
[BOJ] #2470. 두 용액 / 골드5 / 30분 / 성공
1 parent 97f454c commit f7259b3

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import sys
2+
input = sys.stdin.readline
3+
4+
N = int(input()) # 전체 용액의 수
5+
liquid = sorted(map(int, input().split()))
6+
7+
left = 0
8+
right = N - 1
9+
10+
# 초기값 설정
11+
answer = abs(liquid[left] + liquid[right])
12+
answer_liquid = [liquid[left], liquid[right]]
13+
14+
while left < right:
15+
temp = liquid[left] + liquid[right]
16+
# 합이 0에 더 가까우면 정답 갱신
17+
if abs(temp) < answer:
18+
answer = abs(temp)
19+
answer_liquid = [liquid[left], liquid[right]]
20+
# 포인터 이동
21+
if temp < 0:
22+
left += 1
23+
else:
24+
right -= 1
25+
26+
print(answer_liquid[0], answer_liquid[1])

0 commit comments

Comments
 (0)