๋ฌธ์
https://www.acmicpc.net/problem/2470
ํ์ด
# ๋ฐฑ์ค 2470๋ฒ ๋ฌธ์ - ๋ ์ฉ์ก
n = int(input())
arr = sorted(list(map(int, input().split())))
left = 0
right = n-1
answer = abs(arr[left] + arr[right])
check = [arr[left], arr[right]]
while left < right:
s = arr[left] + arr[right]
if abs(s) < answer:
answer = abs(s)
check = [arr[left], arr[right]]
if answer == 0:
break
if s < 0:
left += 1
else:
right -= 1
print(check[0], check[1])
ํฌ ํฌ์ธํฐ ๋ฌธ์ ์ด๋ค. ์ด์ ์ ํ์ด๋ดค๋ ํฌ ํฌ์ธํฐ ๋ฌธ์ ์ ๋น์ทํด์ ํ ์ ์์๋ค.
์ฃผ์ด์ง ์กฐ๊ฑด์ด ์ ๋ ฌ๋์ด ์๊ณ left ์ right ํฌ์ธํฐ๋ฅผ ํฌ๊ธฐ์ ๋ฐ๋ผ ์กฐ์ ํด์ค๋ค.
'๐๏ธ Algorithm > ๐ฉ ๋ฐฑ์ค' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
๐ฉ [๋ฐฑ์ค] [Python] [Silver1] 11057๋ฒ_์ค๋ฅด๋ง ์ (2) | 2023.05.02 |
---|---|
๐ฉ [๋ฐฑ์ค] [Python] [Gold5] 17070๋ฒ_ํ์ดํ ์ฎ๊ธฐ๊ธฐ 1 (0) | 2023.05.01 |
๐ฉ [๋ฐฑ์ค] [Python] [Gold5] 2565๋ฒ_์ ๊น์ค (0) | 2023.04.29 |
๐ฉ [๋ฐฑ์ค] [Python] [Gold3] 2638๋ฒ_์น์ฆ (1) | 2023.04.28 |
๐ฉ [๋ฐฑ์ค] [Python] [Gold5] 2225๋ฒ_ํฉ ๋ถํด (0) | 2023.04.27 |