Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
N = int(input())
sol = list(map(int, input().split()))
sol.sort()

result = [1000000000, 1000000000, 1000000000]
for k in range(N):
i = k + 1
j = N - 1
while i < j:
if abs(sol[i] + sol[j] + sol[k]) < abs(sum(result)):
result = [sol[k], sol[i], sol[j]]

if sol[i] + sol[j] + sol[k] > 0:
j -= 1
elif sol[i] + sol[j] + sol[k] < 0:
i += 1
else:
break

print(*result)
17 changes: 17 additions & 0 deletions _WeeklyChallenges/W20-[TwoPointer]/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
## 🚀4월 3주차 (4/21) 스터디 발제 주제: Two Pointer, Binary Search
> 발제자: 조윤상 (@YoonYn9915)

> [!NOTE]
> 주제: Two Pointer, Binary Search

### 🗂️ 스터디 자료
- PDF: [바로가기
](Study_BOJ_2240.pdf)

### 📖 문제
- [백준 #2240. 두 용액](https://www.acmicpc.net/problem/2240): Two Pointer, Binary Search / 골드 5
- 정답 코드: [Study_BOJ_2240_두 용액.py](Study_BOJ_1759_암호만들기.py)

### 💻 과제
- [백준 #2473. 세 용액](https://www.acmicpc.net/problem/2473): Two Pointer, Binary Search / 골드 3
- 정답 코드: [Assignment_BOJ_2473_세 용액.py](Assignment_BOJ_2473_세 용액.py)
Binary file not shown.
27 changes: 27 additions & 0 deletions _WeeklyChallenges/W20-[TwoPointer]/Study_BOJ_2470_두 용액.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import sys

N = int(sys.stdin.readline())
arr = sorted(map(int, sys.stdin.readline().split()))

left = 0
right = N - 1

answer = (arr[left], arr[right], abs(arr[left] + arr[right]))

# 투 포인터 사용해서 절대값이 0에 가장 가까운 두 값 찾기
while left < right:
total = arr[left] + arr[right]
abs_total = abs(total)

if abs_total < answer[2]:
answer = (arr[left], arr[right], abs_total)
if abs_total == 0:
break
# 두 용액의 값이 0보다 크면 right를 줄여서 합을 작게 만든다
if total > 0:
right -= 1
else:
# 두 용액의 값이 0보다 작으면 left를 늘려서 합을 크게 만든다
left += 1

print(f"{answer[0]} {answer[1]}")