λ΄ μ½λ
def find(lans, n,h,m):
high = h
min = m
mid = (high + min)//2
while min <= high:
sum = 0
for lan in lans:
sum += lan//mid
if sum >= n:
min = mid + 1
elif sum < n:
high = mid - 1
mid = (high + min)//2
return mid
from sys import stdin
k, n = map(int,stdin.readline().split())
lans = []
for i in range(k):
lans.append(int(input()))
high = max(lans)
min = 1
mid1 = find(lans,n,high,min)
print(mid1)
μ²μ μμ±ν μ½λ
k,n = map(int,input().split())
lans = []
for i in range(k):
lans.append(int(input()))
max = 1
sum = [0]
while True:
sum.append(0)
for lan in lans:
sum[max] += (lan//max)
if sum[max] == 0:
break
max += 1
a = 0
for i in range(max):
if (a < i) & (sum[i] >= n):
a = i
print(a)
μ μ μ‘°μ¬λ‘ νμ΄λ³΄λ € νμ§λ§... μκ° μ΄κ³Όκ° λ°μνλ€.
μκ° μ΄κ³Όκ° λλ μ΄μ λ₯Ό μμ² ν€λ§€κ³ , μ½λ μμ λ λ§μ΄ ν΄λ΄€μ§λ§ ν΄κ²°μ΄ λμ§ μμ κ²°κ΅ κ΅¬κΈλ§ νλ€.
λ°©λ²μ μ΄μ§ νμμ μ¬μ©νλ κ²μ΄μλ€.
μ΄μ§ νμ μ½λ
k,n = map(int,input().split())
lans = []
for i in range(k):
lans.append(int(input()))
mid = max(lans)//2
high = max(lans)
min = 0
while True:
sum = 0
for lan in lans:
sum += lan//mid
if n == sum:
break
elif sum > n:
min = mid + 1
mid = (high + min)//2
else:
high = mid - 1
mid = (high + min)//2
if min > high:
n += 1
mid = max(lans)//2
high = max(lans)
min = 0
print(mid - 1)
λΆλͺ μ΄μ§ νμμ ν΅ν΄ μκ°μ΄κ³Όλ ν΄κ²°νμΌλ.. μ΄μ§νμμ ν΅ν΄ λμ€λ κ²°κ΄κ°μ΄ μ΅λκ°μ΄ μλμλ€.
μ΅λκ°μ μ°ΎκΈ° μν΄, λ€μκ³Ό κ°μ μ½λλ₯Ό μΆκ°νμΌλ..
k,n = map(int,input().split())
lans = []
lansum = 0
for i in range(k):
lans.append(int(input()))
mid = max(lans)//2
high = max(lans)
min = 0
while True:
sum = 0
for lan in lans:
sum += lan//mid
if n == sum:
break
elif sum > n:
min = mid + 1
mid = (high + min)//2
else:
high = mid - 1
mid = (high + min)//2
if min > high:
n += 1
mid = max(lans)//2
high = max(lans)
min = 0
while True:
sum = 0
for lan in lans:
sum += lan//mid
if n == sum:
mid += 1
else:
break
print(mid - 1)
λλ€μ μκ° μ΄κ³Ό λ°μ... λ€μ μ΅λκ°μ ꡬνλ μ½λλ₯Ό μ§λ©΄μ μμ²λ μ½μ§μ ν κ²°κ³Ό
λ€μκ³Ό κ°μ λλ¬μ΄ μ½λκ° νμνλ€..
def find(lans, n,h,m,l):
low = l
high = h
min = m
mid = (high + min)//2
while True:
sum = 0
for lan in lans:
sum += lan//mid
if sum == n:
break
elif sum > n:
min = mid + 1
elif sum < n:
high = mid - 1
if min > high:
if low == False:
n += 1
else:
n -= 1
high = h
min = m
mid = (high + min)//2
return mid,n
k,n = map(int,input().split())
lans = []
for i in range(k):
lans.append(int(input()))
if k == n:
print(lans[0])
exit(0)
high = max(lans)
min = 0
mid1,n1 = find(lans,n,high,min,False)
mid2,n2 = find(lans,n-1,high,min,True)
while True:
mid3,n3 = find(lans,n,mid2,mid1,False)
if mid1 == mid3:
break
if n3 == n1:
mid1 = mid3
print(mid1)
λ¬Όλ‘ μ΄ μ½λλ‘λ μκ°μ΄κ³Ό λ¬Έμ λ ν΄κ²°μ΄ λμ§ μμκ³ .. κ²°κ΅ κ΅¬κΈλ§μ ν΅ν΄ λ¬Έμ λ₯Ό νμλ€.
μ΄ λ¬Έμ λ₯Ό νλ©° μ»μ κ΅νμ..
3μκ° μ΄μ ν¬μν΄λ λ¬Έμ κ° μ ν리면 ν루 κ°κ²©μ λκ³ νμ΄λ³΄κ³ ,
μ½λκ° λ무 볡μ‘ν΄μ§λ€κ³ λλΌλ©΄ λ€μ μκ°ν΄μΌκ² λ€.