diff --git "a/_WeeklyChallenges/W20-[TwoPointer]/Assignment_BOJ_2473_\354\204\270 \354\232\251\354\225\241.py" "b/_WeeklyChallenges/W20-[TwoPointer]/Assignment_BOJ_2473_\354\204\270 \354\232\251\354\225\241.py" new file mode 100644 index 0000000..4510a53 --- /dev/null +++ "b/_WeeklyChallenges/W20-[TwoPointer]/Assignment_BOJ_2473_\354\204\270 \354\232\251\354\225\241.py" @@ -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) \ No newline at end of file diff --git a/_WeeklyChallenges/W20-[TwoPointer]/README.md b/_WeeklyChallenges/W20-[TwoPointer]/README.md new file mode 100644 index 0000000..eadfb54 --- /dev/null +++ b/_WeeklyChallenges/W20-[TwoPointer]/README.md @@ -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) diff --git a/_WeeklyChallenges/W20-[TwoPointer]/Study_BOJ_2240.pdf b/_WeeklyChallenges/W20-[TwoPointer]/Study_BOJ_2240.pdf new file mode 100644 index 0000000..42ca8fd Binary files /dev/null and b/_WeeklyChallenges/W20-[TwoPointer]/Study_BOJ_2240.pdf differ diff --git "a/_WeeklyChallenges/W20-[TwoPointer]/Study_BOJ_2470_\353\221\220 \354\232\251\354\225\241.py" "b/_WeeklyChallenges/W20-[TwoPointer]/Study_BOJ_2470_\353\221\220 \354\232\251\354\225\241.py" new file mode 100644 index 0000000..7b3c625 --- /dev/null +++ "b/_WeeklyChallenges/W20-[TwoPointer]/Study_BOJ_2470_\353\221\220 \354\232\251\354\225\241.py" @@ -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]}") \ No newline at end of file