๋ฌธ์
https://www.acmicpc.net/problem/2110
ํ์ด
# ๋ฐฑ์ค 2110๋ฒ ๋ฌธ์ - ๊ณต์ ๊ธฐ ์ค์น
import sys
input = sys.stdin.readline
n, c = map(int, input().split())
x = []
for i in range(n):
x.append(int(input()))
x.sort()
def binary_search(x, start, end):
while start <= end:
mid = (start+end) // 2
cur = x[0]
cnt = 1
for i in range(1, len(x)):
if x[i] >= cur + mid:
cnt += 1
cur = x[i]
if cnt >= c:
global answer
start = mid + 1
answer = mid
else:
end = mid - 1
start = 1
end = x[-1] - x[0]
answer = 0
binary_search(x, start, end)
print(answer)
์ฃผ์ํด์ผ ํ ์ ์ sys๋ชจ๋์ ์ฌ์ฉํ์ง ์์ผ๋ฉด Python3 ์์ ์๊ฐ์ด๊ณผ๊ฐ ๋ฐ์ํ์๋ค.
'๐๏ธ Algorithm > ๐ฉ ๋ฐฑ์ค' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
๐ฉ [๋ฐฑ์ค] [Python] [Gold4] [์ผ์ฑ SW ์ญ๋ ํ ์คํธ ๊ธฐ์ถ ๋ฌธ์ ] 14499๋ฒ_์ฃผ์ฌ์ ๊ตด๋ฆฌ๊ธฐ (0) | 2023.02.24 |
---|---|
๐ฉ [๋ฐฑ์ค] [Python] [Gold4] 3190๋ฒ_๋ฑ (0) | 2023.02.23 |
๐ฉ [๋ฐฑ์ค] [Python] [Gold3] 16236๋ฒ_์๊ธฐ ์์ด (0) | 2023.02.21 |
๐ฉ [๋ฐฑ์ค] [Python] [Gold2] 1300๋ฒ_K๋ฒ์งธ ์ (0) | 2023.02.20 |
๐ฉ [๋ฐฑ์ค] [Python] [Gold4] 10830๋ฒ_ํ๋ ฌ ์ ๊ณฑ (0) | 2023.02.20 |