We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 97f454c commit f7259b3Copy full SHA for f7259b3
1 file changed
_WeeklyChallenges/W08-[TwoPointer]/2025-04-21-[백준]-#2470-두용액.py
@@ -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