input
stringlengths 20
127k
| target
stringlengths 20
119k
| problem_id
stringlengths 6
6
|
---|---|---|
from heapq import heappush, heappop
def main():
N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
h = []
for a in A:
heappush(h, [-a, a, 1])
for i in range(K):
pri, origlen, cut = heappop(h)
heappush(h, [-origlen//(cut+1), origlen, cut+1])
ans = -h[0][0]
print(ans)
if __name__ == "__main__":
main()
|
def countcut(A, length):
ret = 0
for a in A:
ret += -(-a//length) - 1
return ret
def main():
N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
lo = 1
hi = int(1e9)
while lo < hi:
mid = (lo+hi) // 2
if countcut(A, mid) <= K:
hi = mid
else:
lo = mid + 1
print(lo)
if __name__ == "__main__":
main()
|
p02598
|
# coding: utf-8
def solve(*args: str) -> str:
n, k = list(map(int, args[0].split()))
A = tuple(map(int, args[1].split()))
l, r = 1, max(A)
while 1e-3 < r-l:
m = (l+r)/2
cnt = 0
for a in A:
cnt += -int(-a//m)-1
if k < cnt:
l = m
else:
r = m
return str(-int(-l//1))
if __name__ == "__main__":
print((solve(*(open(0).read().splitlines()))))
|
# coding: utf-8
def solve(*args: str) -> str:
n, k = list(map(int, args[0].split()))
A = tuple(map(int, args[1].split()))
l, r = 1, max(A)
while 0.1 < r-l:
m = (l+r)/2
cnt = 0
for a in A:
cnt += -int(-a//m)-1
if k < cnt:
l = m
else:
r = m
return str(-int(-l//1))
if __name__ == "__main__":
print((solve(*(open(0).read().splitlines()))))
|
p02598
|
# coding: utf-8
def solve(*args: str) -> str:
n, k = list(map(int, args[0].split()))
A = tuple(map(int, args[1].split()))
l, r = 1, max(A)
while 0.1 < r-l:
m = (l+r)/2
cnt = 0
for a in A:
cnt += -int(-a//m)-1
if k < cnt:
l = m
else:
r = m
return str(-int(-l//1))
if __name__ == "__main__":
print((solve(*(open(0).read().splitlines()))))
|
# coding: utf-8
def solve(*args: str) -> str:
n, k = list(map(int, args[0].split()))
A = tuple(map(int, args[1].split()))
l, r = 0, max(A)
while l+1 < r:
m = (l+r)//2
cnt = 0
for a in A:
cnt += -(-a//m)-1
if k < cnt:
l = m
else:
r = m
return str(r)
if __name__ == "__main__":
print((solve(*(open(0).read().splitlines()))))
|
p02598
|
import heapq
from math import ceil
N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
hp = []
for log in A:
heapq.heappush(hp, (-log, log, 1))
for i in range(K):
cur_length, length, count = heapq.heappop(hp)
cur_length = -cur_length
new_length = length / (count + 1)
heapq.heappush(hp, (-new_length, length, count + 1))
print((ceil(-hp[0][0])))
|
from math import ceil
N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
def possible(A, K, target):
count = 0
for a in A:
count += ceil(a / target) - 1
return count <= K
left = 1
right = max(A)
while left < right:
mid = (left + right) // 2
if possible(A, K, mid):
right = mid
else:
left = mid + 1
print(right)
|
p02598
|
import math, heapq
N, K = list(map(int, input().split()))
a = list(map(int, input().split()))
a.sort(reverse=True)
lst = []
for i in a:
lst.append([-i, 0])
heapq.heapify(lst)
for i in range(K):
p = heapq.heappop(lst)
p[1] += 1
p[0] = p[0] * p[1] / (p[1] + 1)
heapq.heappush(lst, p)
p = heapq.heappop(lst)
print((math.ceil(-p[0])))
|
import math
N, K = list(map(int, input().split()))
a = list(map(int, input().split()))
def cal(x):
s = 0
for aa in a:
s += math.ceil(aa / x) - 1
if s <= K: return True
else: return False
l = 0
r = max(a)
while abs(r - l) > 1:
mid = (l + r) // 2
if cal(mid):
r = mid
else:
l = mid
print(r)
|
p02598
|
#!/usr/bin/env python3
import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def f(x):
cnt = k
for i in a:
tmp = math.ceil(i / x)
cnt -= tmp - 1
if cnt < 0:
return False
return True
n, k = LI()
a = LI()
a.sort(reverse=True)
ok = sum(a)
ng = 0
while ok - ng > 1:
mid = (ok + ng) // 2
if f(mid):
ok = mid
else:
ng = mid
print(ok)
|
#!/usr/bin/env python3
n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
def f(x):
cnt = 0
for i in a:
cnt += (i-1) // x
if cnt > k:
return False
return True
ok = 10**9
ng = 0
while ok - ng > 1:
mid = (ok + ng) // 2
if f(mid):
ok = mid
else:
ng = mid
print(ok)
|
p02598
|
from heapq import heappop, heappush, heapify
n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
q = []
for x in a:
heappush(q, (-x, 1, x))
for i in range(k):
_, dc, p = heappop(q)
dc += 1
v = -(-p//dc)
heappush(q, (-v, dc, p))
ans = 0
for x, _, _ in q: ans = max(ans, -x)
print(ans)
|
n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
def f(m):
res = sum([-(-x//m)-1 for x in a])
return res <= k
l, r = 0, 10**9+10
while r-l > 1:
x = (l+r)//2
if f(x): r = x
else: l = x
print(r)
|
p02598
|
N,K=list(map(int,input().split()))
alist=list(map(int,input().split()))
#print(alist)
def num_cut(x):
if x==0:
return False
ret=0
for a in alist:
ret+=-(-(a-x)//x)
return ret
#for i in range(1,max(alist)):
# print(i,num_cut(i))
l=1
r=max(alist)+1
while l<=r:
mid=(l+r)//2
#print(l,mid,r)
if num_cut(mid-1)>K and num_cut(mid)<=K:
print(mid)
break
elif num_cut(mid)<=K:
r=mid
else:
l=mid
|
N,K=list(map(int,input().split()))
alist=list(map(int,input().split()))
#print(alist)
def num_cut(x):
if x==0:
return float("inf")
ret=0
for a in alist:
ret+=-(-(a-x)//x)
return ret
#for i in range(1,max(alist)):
# print(i,num_cut(i))
l=1
r=max(alist)+1
while l<=r:
mid=(l+r)//2
#print(l,mid,r)
if num_cut(mid-1)>K and num_cut(mid)<=K:
print(mid)
break
elif num_cut(mid)<=K:
r=mid
else:
l=mid
|
p02598
|
N,K=list(map(int,input().split()))
alist=list(map(int,input().split()))
#print(alist)
def num_cut(x):
if x==0:
return float("inf")
ret=0
for a in alist:
ret+=-(-(a-x)//x)
return ret
#for i in range(1,max(alist)):
# print(i,num_cut(i))
l=1
r=max(alist)+1
while l<=r:
mid=(l+r)//2
#print(l,mid,r)
if num_cut(mid-1)>K and num_cut(mid)<=K:
print(mid)
break
elif num_cut(mid)<=K:
r=mid
else:
l=mid
|
N,K=list(map(int,input().split()))
alist=list(map(int,input().split()))
#print(alist)
memo={0:False}
def isOK(x):
if x in memo:
return memo[x]
num_cut=0
for a in alist:
num_cut+=-(-(a-x)//x)
if num_cut>K:
memo[x]=False
return False
memo[x]=True
return True
l=1
r=max(alist)+1
while l<=r:
mid=(l+r)//2
if not isOK(mid-1) and isOK(mid):
print(mid)
break
elif isOK(mid-1):
r=mid
else:
l=mid
|
p02598
|
from heapq import heappush, heappop
from math import ceil
def main():
n, k = list(map(int, input().split()))
a = [int(i) for i in input().split()]
c = [1] * n
h = []
for i, ai in enumerate(a):
heappush(h, (-ai, i))
for _ in range(k):
ai, i = heappop(h)
ci = c[i]
ai = ai * ci / (ci + 1)
heappush(h, (ai, i))
c[i] += 1
print((ceil(-h[0][0])))
if __name__ == '__main__':
main()
|
from math import ceil
def main():
n, k = list(map(int, input().split()))
a = sorted([int(i) for i in input().split()], reverse=True)
left = 0
right = a[0]
while right - left > 1:
ki = k
mid = left + (right - left) // 2
for ai in a:
if ki < 0:
left = mid
break
if ai <= mid:
right = mid
break
ki -= ceil(ai / mid) - 1
else:
if ki < 0:
left = mid
else:
right = mid
print(right)
if __name__ == '__main__':
main()
|
p02598
|
import heapq
import math
n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
a.sort(reverse=True)
if k == 0:
print((a[0]))
exit(0)
mean_a = sum(a) / k
q = []
for aa in a:
d = max(math.floor(aa / mean_a)-2, 1)
q.append((-aa/d, d))
k -= (d-1)
heapq.heapify(q)
for _ in range(k):
aa, n = heapq.heappop(q)
heapq.heappush(q, (aa*n/(n+1), n+1))
ans, _ = heapq.heappop(q)
print((math.ceil(-ans)))
|
import heapq
import math
n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
a.sort(reverse=True)
if k == 0:
print((a[0]))
exit(0)
mean_a = sum(a) / k
q = []
for aa in a:
d = max(math.floor(aa / mean_a)-1, 1)
q.append((-aa/d, d))
k -= (d-1)
heapq.heapify(q)
for _ in range(k):
aa, n = heapq.heappop(q)
heapq.heappush(q, (aa*n/(n+1), n+1))
ans, _ = heapq.heappop(q)
print((math.ceil(-ans)))
|
p02598
|
import math
import heapq
N, K = list(map(int, input().split()))
A = sorted([(-int(i), int(i), 1) for i in input().split()])
heapq.heapify(A) # リストhqのheap化
for _ in range(K):
_, L, T = heapq.heappop(A) # heap化されたリストhqから最小値を削除&その最小値を出力
heapq.heappush(A, (-L/(T+1), L, T+1)) # heap化されたリストhqに要素xを追加
_, L, T = heapq.heappop(A)
print((math.ceil(L/T)))
|
N, K = list(map(int, input().split()))
A = [int(i) for i in input().split()]
OK = 10**12
NG = 0
while OK-NG > 1:
mid = (OK+NG)//2
cnt = 0
for a in A:
cnt += (a-1)//mid
if cnt <= K:
OK = mid
else:
NG = mid
# print('OK:{}, NG:{}, cnt:{}'.format(OK, NG, cnt))
print(OK)
|
p02598
|
import heapq
n,k = list(map(int,input().split()))
a = [int(i) for i in input().split()]
hq = []
for i in range(n):
a[i] = -a[i]
for i in range(n):
heapq.heappush(hq,[a[i],i,1])
for i in range(k):
val,idx,waru = heapq.heappop(hq)
heapq.heappush(hq, [a[idx]/(waru+1),idx,waru+1])
#print(hq)
val,idx,waru = heapq.heappop(hq)
if val % 1 == 0:
print((int(val)*(-1)))
else:
print((int(val)*(-1)+1))
|
import heapq
n,k = list(map(int,input().split()))
a = [int(i) for i in input().split()]
low = 0
high = 10**9
if k == 0:
print((max(a)))
exit()
while low+1 < high:
tmp = 0
mid = (low + high) //2
for i in range(n):
tmp += ((a[i]+mid-1) // mid)-1
if tmp <= k:
high = mid
else:
low = mid
print(high)
|
p02598
|
import heapq
import math
import sys
input = sys.stdin.readline
def main():
N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
for i in range(N):
p = A[i]
A[i] = [-p, i]
heapq.heapify(A)
C = [0]*N
for j in range(K):
x, y = heapq.heappop(A)
cnt = C[y]
x = x * (cnt+1) / (cnt+2)
C[y] += 1
heapq.heappush(A, [x, y])
ans = heapq.heappop(A)[0]
ans = math.ceil(-ans)
print(ans)
if __name__ == "__main__":
main()
|
import heapq
import math
import sys
input = sys.stdin.readline
def main():
N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
def C(m):
cnt = 0
for i in range(N):
cnt += math.ceil(A[i]/m)-1
return cnt
l, r = 0, max(A)
while r - l > 1:
mid = (l+r)//2
if C(mid) <= K:
r = mid
else:
l = mid
print(r)
if __name__ == "__main__":
main()
|
p02598
|
def main():
import sys
def input(): return sys.stdin.readline().rstrip()
n , k = list(map(int, input().split()))
a = list(map(int, input().split()))
l = 1
r = max(a)
while l < r:
m = (l+r)//2
cnt = 0
for x in a:
cnt += (x-1)//m
if cnt > k: l = m+1
else: r = m
print(r)
if __name__ == '__main__':
main()
|
def main():
import sys
def input(): return sys.stdin.readline().rstrip()
n , k = list(map(int, input().split()))
a = list(map(int, input().split()))
def check(m):
cnt = 0
for x in a:
cnt += (x-1)//m
return cnt <= k
l, r = 0, max(a)
while r-l > 1:
m = (r+l)//2
if check(m): r = m
else: l = m
print(r)
if __name__ == '__main__':
main()
|
p02598
|
import heapq
import math
n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
lst = []
for i in range(n):
lst.append([-a[i], 1])
heapq.heapify(lst)
for i in range(k):
pop = heapq.heappop(lst)
pop = [pop[0]*(pop[1])/(pop[1]+1), pop[1]+1]
heapq.heappush(lst, pop)
pop = heapq.heappop(lst)
print((math.ceil(-pop[0])))
|
n, k = list(map(int, input().split()))
log = list(map(int, input().split()))
left = 0
right = 10**9
while right - left > 1:
mid = (left + right) // 2
cut = 0
for i in range(n):
cut += -(log[i]//-mid)-1
if cut > k:
left = mid
else:
right = mid
print(right)
|
p02598
|
from heapq import heappop,heappush
from math import ceil
n,k=list(map(int,input().split()))
a=list(map(int,input().split()))
hq=[]
for x in a:
heappush(hq,[-x,1])
for i in range(k):
r=heappop(hq)
heappush(hq,[r[0]*r[1]/(r[1]+1),r[1]+1])
ans=-heappop(hq)[0]
print((ceil(ans)))
|
n,k=list(map(int,input().split()))
a=list(map(int,input().split()))
l=0
r=max(a)+1
while r-l>1:
cnt=0
mid=(l+r+1)//2
if mid==0:
print((1))
exit()
for x in a:
if x>1:
cnt+=(x-1)//mid
if cnt<=k:
r=mid
else:
l=mid
print(r)
|
p02598
|
import heapq
n , k = list(map(int,input().split()))
p = list(map(int,input().split()))
a = []
for i in range(n):
a.append([-p[i],-p[i],1])
heapq.heapify(a)
for i in range(k):
now , moto , kazu = heapq.heappop(a)
heapq.heappush(a,[moto//(kazu+1),moto,kazu+1])
ans = heapq.heappop(a)
print((-ans[0]))
|
import heapq
n , k = list(map(int,input().split()))
a = list(map(int,input().split()))
lef = 0
rig = max(a)
while rig - lef != 1:
now = -(-(lef+rig)//2)
cou = 0
for i in range(n):
cou += -(-a[i]//now) - 1
if cou <= k:
rig = now
elif cou > k:
lef = now
print(rig)
|
p02598
|
n,k = list(map(int,input().split()))
p = list(map(int,input().split()))
import copy
a = copy.deepcopy(p)
for i in range(n):
a[i] = [-a[i],0,i]
import heapq as hp
hp.heapify(a)
for i in range(k):
s = hp.heappop(a)
u = [s[0]/2,s[1]+1,s[2]]
hp.heappush(a, u)
ans = 0
for i in range(n):
ans = max(-(-p[a[i][2]]//(a[i][1]+1)),ans)
print(ans)
|
n,k = list(map(int,input().split()))
a = list(map(int,input().split()))
ans = 0
def test(d,m,u):
global ans
p = 0
for i in range(n):
if m < a[i]:
p += a[i]//m
if u-d <= 1:
ans = max(ans,m)
pass
elif p > k:
ans = max(ans,m)
d = m
m = -(-(m+u)//2)
test(d,m,u)
else:
u = m
m = -(-(m+d)//2)
test(d,m,u)
d = 0
m = 1
u = 10**9+7
test(d,m,u)
print(ans)
|
p02598
|
from math import ceil
from heapq import heapify, heappop, heappush
N, K, *A = list(map(int, open(0).read().split()))
a = [(-i, i, 1) for i in A]
heapify(a)
for _ in range(K):
i, j, k = heappop(a)
k += 1
i = -(j / k)
heappush(a, (i, j, k))
print((ceil(heappop(a)[0] * -1)))
|
from math import ceil
N, K, *A = list(map(int, open(0).read().split()))
def is_ok(n):
t = 0
for a in A:
if a <= n:
continue
t += ceil(a / n) - 1
return t <= K
ok = 1000000000
ng = 0.0000000001
while abs(ng - ok) > 1:
m = (ok + ng) // 2
if is_ok(m):
ok = m
else:
ng = m
print((ceil(ok)))
|
p02598
|
import math
N, K=list(map(int, input().split()))
A=list(map(int, input().split()))
i=1
j=10**9
while True:
k=(i+j)//2
if k>0 and sum([math.ceil(a/k)-1 for a in A])<=K:
if k-1>0 and sum([math.ceil(a/(k-1))-1 for a in A])>K:
print(k)
break
else:
j=k-1
else:
i=k+1
|
import math
N, K=list(map(int, input().split()))
A=list(map(int, input().split()))
i=1
j=10**9
while True:
k=(i+j)//2
if k>0 and sum([math.ceil(a/k)-1 for a in A])<=K:
if k==1 or sum([math.ceil(a/(k-1))-1 for a in A])>K:
print(k)
break
else:
j=k-1
else:
i=k+1
|
p02598
|
import math
def possible(l, a, k):
for x in a:
k -= math.ceil(x/l)-1
return k>=0
n, k = list(map(int, input().split()))
a = [int(x) for x in input().split()]
mini = 1
maxi = 10**9+7
while(mini!=maxi):
mid = (mini+maxi)//2
if possible(mid, a, k):
maxi = mid
else:
mini = mid + 1
print(mini)
|
import math
def possible(l, a, k):
for x in a:
k -= x//l
if x%l==0:
k += 1
return k>=0
n, k = list(map(int, input().split()))
a = [int(x) for x in input().split()]
mini = 1
maxi = 10**9+7
while(mini!=maxi):
mid = (mini+maxi)//2
if possible(mid, a, k):
maxi = mid
else:
mini = mid + 1
print(mini)
|
p02598
|
import copy
import math
N, K = list(map(int,input().split()))
As = list(map(int,input().split()))
sorted_As = sorted(As,reverse = True)
cut_As = copy.copy(sorted_As)
count_list = [0]*len(sorted_As)
for i in range(K):
index = cut_As.index(max(cut_As))
count = count_list[index]
count_list[index] += 1
cut_As[index] = sorted_As[index] / (count+2)
'''
for i in range(K):
count = count_list[0]
count_list[0] += 1
cut_As[0] = sorted_As[0] / (count+2)
cut_As,sorted_As,count_list = (list(x) for x in zip(*sorted(zip(cut_As,sorted_As,count_list),reverse = True)))
'''
print((math.ceil(max(cut_As))))
|
def judge(As,K,C):
count = 0
for i in range(len(As)):
if As[i]%C == 0:
m = As[i]//C - 1
else:
m = As[i]//C
count += m
if count <= K:
return True
else:
return False
N, K = list(map(int,input().split()))
As = list(map(int,input().split()))
l = 0
r = max(As)
while(r-l>1):
mid = (l+r)//2
if judge(As,K,mid):
r = mid -1
else:
l = mid + 1
if judge(As,K,r):
print(r)
else:
print((r+1))
|
p02598
|
import sys
import math
import heapq
push = heapq.heappush
pop = heapq.heappop
readline = sys.stdin.buffer.readline
def even(n): return 1 if n%2==0 else 0
n,k = list(map(int,readline().split()))
lst1 = list(map(int,readline().split()))
hp = []
for i in lst1:
push(hp,(-i,i,1))
for i in range(k):
res = pop(hp)
res2 = [0]*3
res2[0] = -res[1]/(res[2]+1)
res2[1] = res[1]
res2[2] = res[2]+1
push(hp,tuple(res2))
print((math.ceil(-pop(hp)[0])))
|
#揃える長さを決め打って二分探索
import sys
import math
readline = sys.stdin.buffer.readline
def even(n): return 1 if n%2==0 else 0
n,k = list(map(int,readline().split()))
lst1 = list(map(int,readline().split()))
lst1.sort(reverse=True)
def func(mid): #ここが関数部分
res = 0
for i in range(n):
if mid >= lst1[i]:
continue
res += math.ceil(lst1[i]/mid)-1
if res > k:
return False
return True
def binary_search(): #2分探索
ok = 10**9
ng = 0
while abs(ok-ng)>1:
mid = (ok+ng)//2
if func(mid):
ok = mid
else:
ng = mid
return ok
print((binary_search()))
|
p02598
|
from fractions import Fraction
from math import ceil, floor
N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
def isOk(x):
cnt = 0
for a in A:
cnt += floor(Fraction(a, x))
return cnt <= K
ok = max(A)
ng = 0
for _ in range(50):
mid = Fraction(ok + ng, 2)
if isOk(mid):
ok = mid
else:
ng = mid
print((ceil(ok)))
|
N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
def isOk(x):
cnt = 0
for a in A:
cnt += (a - 1) // x
return cnt <= K
ok = max(A)
ng = 0
while ok - ng > 1:
mid = (ok + ng) // 2
if isOk(mid):
ok = mid
else:
ng = mid
print(ok)
|
p02598
|
import sys
import math
def input():
return sys.stdin.readline().rstrip()
def main():
N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
ng = 0
ok = 10 ** 9 + 1
while ok - ng > 1:
mid = (ok + ng) // 2
ans = sum(list([math.ceil(x / mid) - 1 for x in A]))
# for i in range(N):
# ans += A[i]//mid -1
# if A[i]%mid !=0:
# ans +=1
if ans <= K:
ok = mid
else:
ng = mid
print(ok)
if __name__ == "__main__":
main()
|
import sys
def input():
return sys.stdin.readline().rstrip()
def main():
N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
ng = 0
ok = 10 ** 9 + 1
A.sort(reverse=True)
while ok - ng > 1:
mid = (ok + ng) // 2
ans =0
for i in range(N):
ans += A[i]//mid -1
if A[i]%mid !=0:
ans +=1
if ans >K:
break
if ans <= K:
ok = mid
else:
ng = mid
print(ok)
if __name__ == "__main__":
main()
|
p02598
|
import sys
def input():
return sys.stdin.readline().rstrip()
def main():
N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
ng = 0
ok = 10 ** 9 + 1
A.sort(reverse=True)
while ok - ng > 1:
mid = (ok + ng) // 2
ans =0
for i in range(N):
ans += A[i]//mid -1
if A[i]%mid !=0:
ans +=1
if ans >K:
break
if ans <= K:
ok = mid
else:
ng = mid
print(ok)
if __name__ == "__main__":
main()
|
import sys
def input():
return sys.stdin.readline().rstrip()
def main():
N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
ng = 0
ok = 10 ** 9 + 1
while ok - ng > 1:
mid = (ok + ng) // 2
ans =0
for i in range(N):
ans += A[i]//mid -1
if A[i]%mid !=0:
ans +=1
if ans >K:
break
if ans <= K:
ok = mid
else:
ng = mid
print(ok)
if __name__ == "__main__":
main()
|
p02598
|
import heapq
import math
length_heap = []
N, total_cut = list(map(int, input().split()))
length_list = list(map(int, input().split()))
for index, l in enumerate(length_list):
heapq.heappush(length_heap, (-l, 1, index))
for i in range(total_cut):
longest, cut_n, idx = heapq.heappop(length_heap)
heapq.heappush(length_heap, (-length_list[idx]/(cut_n+1), (cut_n + 1), idx))
result = -heapq.heappop(length_heap)[0]
print((math.ceil(result)))
|
import math
N, K = list(map(int, input().split()))
log_list = list(map(int, input().split()))
maxx = 10**9
minx = 0
while (maxx - minx != 1):
midx = (maxx + minx) // 2
cut_n = sum([math.ceil(length / midx)-1 for length in log_list])
if cut_n > K:
minx = midx
else:
maxx = midx
print(maxx)
|
p02598
|
import heapq
n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
b = [[i, 2] for i in a]
for _ in range(k):
p = a.index(max(a))
if b[p][0]%b[p][1] == 0:
a[p] = b[p][0]//b[p][1]
else:
a[p] = b[p][0]//b[p][1] +1
b[p][1] += 1
print((max(a)))
|
n, k = list(map(int, input().split()))
a = [i-1 for i in map(int, input().split())]
left, right = 0, 10**9
while left < right:
middle = (left+right)//2
if middle==0:
left=1
break
count = 0
for i in a:
count += i//middle
if count <= k:
right = middle
else:
left = middle + 1
print(left)
|
p02598
|
n, k = list(map(int, input().split()))
a = [i-1 for i in map(int, input().split())]
left, right = 0, 10**9
while left < right:
middle = (left+right)//2
if middle==0:
left=1
break
count = 0
for i in a:
count += i//middle
if count <= k:
right = middle
else:
left = middle + 1
print(left)
|
n, k = list(map(int, input().split()))
a = [i-1 for i in map(int, input().split())]
left, right = 1, 10**9
while left < right:
middle = (left + right)//2
count = 0
for i in a:
count += i//middle
if count <= k:
right = middle
else:
left = middle + 1
print(left)
|
p02598
|
from math import ceil
n, k, *A = list(map(int, open(0).read().split()))
t = sum(A) / (n+k)
A = [a for a in A if int(a/t) >= 1]
c = k - sum(int(a/t)-1 for a in A)
X = []
for a in A:
X.append(ceil(a / ceil(a/t)))
X.append(ceil(a / int(a/t)))
X.sort()
print((X[-c-1]))
|
from math import ceil
n, k, *A = list(map(int, open(0).read().split()))
t = sum(A) / (n+k)
A = [a for a in A if int(a/t) >= 1]
X = []
for a in A:
X.append(ceil(a / ceil(a/t)))
X.append(ceil(a / int(a/t)))
X.sort()
print((X[sum(int(a/t)-1 for a in A) -k-1]))
|
p02598
|
import math
N,K=list(map(int,input().split()))
import heapq
A=list(map(int,input().split()))
h=[(-A[i],1) for i in range(len(A))]
heapq.heapify(h)
for i in range(K):
a=heapq.heappop(h)
b=a[0]
c=a[1]
heapq.heappush(h,(c*b/(c+1),c+1))
ans=heapq.heappop(h)
print((math.ceil(-ans[0])))
|
import math
N,K=list(map(int,input().split()))
import heapq
A=list(map(int,input().split()))
def isok(x):
c=0
for i in range(N):
c+=math.ceil(A[i]/x)-1
if c<=K:
return True
else:
return False
start=0
end=max(A)
mid=(start+end)//2
while end-start>1:
mid=(start+end)//2
if isok(mid)==True:
end=mid
else:
start=mid
print(end)
|
p02598
|
n,k = list(map(int,input().split()))
arr = list(map(int,input().split()))
lo = 1
hi = 10**18
ans = max(arr)
while lo<=hi:
t = 0
m = (hi+lo)//2
for i in range(n):
if arr[i]>m:
req = arr[i]//m
else:
req= 0
t+=req
if t<=k:
ans = m
hi = m-1
else:
lo = m+1
print(ans)
|
n,k = list(map(int,input().split()))
arr = list(map(int,input().split()))
lo = 1
hi = 10**12
ans = max(arr)
while lo<=hi:
t = 0
m = (hi+lo)//2
for i in range(n):
if arr[i]>m:
req = arr[i]//m
else:
req= 0
t+=req
if t<=k:
ans = m
hi = m-1
else:
lo = m+1
print(ans)
|
p02598
|
import math
import bisect
N, K = list(map(int, input().split()))
leng = list(map(int, input().split()))
leng.sort()
cut = [0] * N
# A = [maruta(a, 0) for a in A_tmp]
for a in range(K):
new_cut = cut.pop() + 1
new_leng = leng.pop() * (new_cut / (new_cut + 1))
idx = bisect.bisect_left(leng, new_leng)
leng.insert(idx, new_leng)
cut.insert(idx, new_cut)
# print(new_leng, new_cut)
print((math.ceil(leng[-1])))
|
import math
def check(d):
cut_num = 0
for i in leng:
cut_num += math.ceil(i / d) - 1
if cut_num <= K:
return True
return False
N, K = list(map(int, input().split()))
leng = list(map(int, input().split()))
d_min = 0
d_max = max(leng)
d = math.ceil(d_max / 2)
while d_max - d_min > 1:
if check(d):
d_max = d
d = math.ceil((d_max + d_min) / 2)
else:
d_min = d
d = int((d_max + d_min) / 2)
# print(d, d_max, d_min)
print(d_max)
|
p02598
|
def main():
n,k = list(map(int,input().split()))
A = list(map(int,input().split()))
left = 0
right = max(A)
while abs(right-left)>1:
cent = (right+left)//2
ct = 0
for a in A:
ct+=(a-0.1)//cent
if ct <= k:
right=cent
else:
left=cent
print(right)
main()
|
def main():
n,k = list(map(int,input().split()))
A = list(map(int,input().split()))
left = 0
right = max(A)
while abs(right-left)>1:
cent = (right+left)//2
ct = 0
for a in A:
ct+=a//cent
if a%cent==0:
ct-=1
if ct <= k:
right=cent
else:
left=cent
print(right)
main()
|
p02598
|
from math import ceil
def BinarySearch(x):
ans = sum([ceil(a/x)-1 for a in A])
if ans <= K:
return True
else:
return False
N,K = list(map(int,input().split()))
A = list(map(int,input().split()))
r = max(A)
l = 0
eps = 10**-7
while abs(r-l) > eps:
m = (r+l)/2
if BinarySearch(m):
r = m
else:
l = m
print((ceil(r)))
|
from math import ceil
def BinarySearch(x):
ans = sum([ceil(a/x)-1 for a in A])
if ans <= K:
return True
else:
return False
N,K = list(map(int,input().split()))
A = list(map(int,input().split()))
r = max(A)
l = 0
eps = 10**-6
while abs(r-l) > eps:
m = (r+l)/2
if BinarySearch(m):
r = m
else:
l = m
print((ceil(r)))
|
p02598
|
from heapq import heappush, heappop
from math import ceil
N, K = list(map(int, input().split()))
A = [int(i) for i in input().split()]
h = []
for a in A :
heappush(h, (-a, a, 1))
for _ in range(K) :
_, x, i = heappop(h)
heappush(h, (-(x / (i + 1)), x, i + 1))
print((ceil(-h[0][0])))
|
from heapq import heappush, heappop
from math import ceil, floor
N, K = list(map(int, input().split()))
A = [int(i) for i in input().split()]
ng, ok = 0, 10 ** 9
for _ in range(50) :
mid = (ng + ok) / 2
ret = 0
for a in A :
ret += floor(a / mid)
if ret <= K :
ok = mid
else :
ng = mid
print((ceil(ng)))
|
p02598
|
n, k = list(map(int, input().split()))
A = [*list(map(int, input().split()))]
ng, ok = 0, 1<<32 # (ng,ok] = (l,r]
while ok - ng > 1:
m = (ng + ok) // 2
c = 0
for a in A: c += (a-1) // m
if c <= k: ok = m
else: ng = m
print(ok)
|
n, k = list(map(int, input().split()))
A = [*list(map(int, input().split()))]
ng, ok = 0, 1<<30 # (ng,ok] = (l,r]
while ok - ng > 1:
m = (ng + ok) // 2
c = 0
for a in A: c += (a-1) // m
if c <= k: ok = m
else: ng = m
print(ok)
|
p02598
|
n, k = list(map(int, input().split()))
A = [*list(map(int, input().split()))]
A.sort(reverse=True)
ng, ok = 0, 1<<30
while ok - ng > 1:
m = (ng + ok) // 2
c = 0
for a in A:
d = (a - 1) // m
if d == 0: break
c += d
if c <= k: ok = m
else: ng = m
print(ok)
|
_, k = list(map(int, input().split()))
A = [*list(map(int, input().split()))]
ng, ok = 0, 1<<30
while ok - ng > 1:
m = (ng + ok) // 2
if k < sum([(a-1)//m for a in A]): ng = m
else: ok = m
print(ok)
|
p02598
|
# -*- coding: utf-8 -*-
import sys
from decimal import Decimal, ROUND_HALF_UP
def main():
N,K = list(map(int, sys.stdin.readline().split()))
A_list = list(map(int, sys.stdin.readline().split()))
def check(length :int) -> bool:
cnt = 0
for a in A_list:
if a >= length:
quotient = a / length
divide = -(-quotient // 1) # round up
cnt += (divide - 1)
return (True if cnt <= K else False)
L = 0.1 # the minimum length
R = max(A_list) # the maximum length
while (R - L) > 0.01:
M = L + (R - L) / 2
if check(M):
R = M
else:
L = M
ans = float( Decimal(str(M)).quantize(Decimal('1E-1'), rounding=ROUND_HALF_UP) )
ans = -(-ans // 1) # round up
print(( int(ans) ))
if __name__ == "__main__":
main()
|
# -*- coding: utf-8 -*-
import sys
from decimal import Decimal, ROUND_HALF_UP
def main():
N,K = list(map(int, sys.stdin.readline().split()))
A_list = list(map(int, sys.stdin.readline().split()))
def check(length :int) -> bool:
cnt = 0
for a in A_list:
if a >= length:
quotient = a / length
divide = -(-quotient // 1) # round up
cnt += (divide - 1)
return (True if cnt <= K else False)
L = 0 # the minimum length
R = max(A_list) # the maximum length
while (R - L) > 1:
M = L + (R - L) // 2
if check(M):
R = M
else:
L = M
print(R)
if __name__ == "__main__":
main()
|
p02598
|
# -*- coding: utf-8 -*-
import sys
from decimal import Decimal, ROUND_HALF_UP
def main():
N,K = list(map(int, sys.stdin.readline().split()))
A_list = list(map(int, sys.stdin.readline().split()))
def check(length :int) -> bool:
cnt = 0
for a in A_list:
if a >= length:
quotient = a / length
divide = -(-quotient // 1) # round up
cnt += (divide - 1)
return (True if cnt <= K else False)
L = 0 # the minimum length
R = max(A_list) # the maximum length
while (R - L) > 1:
M = L + (R - L) // 2
if check(M):
R = M
else:
L = M
print(R)
if __name__ == "__main__":
main()
|
# -*- coding: utf-8 -*-
import sys
import math
def main():
N,K = list(map(int, sys.stdin.readline().split()))
A_list = list(map(int, sys.stdin.readline().split()))
def check(length :int) -> bool:
cnt = 0
for a in A_list:
if a >= length:
quotient = a / length
#divide = -(-quotient // 1) # round up
divide = math.ceil(quotient) # round up
cnt += (divide - 1)
return (True if cnt <= K else False)
L = 0 # the minimum length
R = max(A_list) # the maximum length
while (R - L) > 1:
M = L + (R - L) // 2
if check(M):
R = M
else:
L = M
print(R)
if __name__ == "__main__":
main()
|
p02598
|
from heapq import heappush, heappop, heapify
n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
def check(x):
# 最長の丸太をx以下にできるか
# 任意の丸太をx以下にできるか
cnt = 0
for ai in a:
if ai > x:
if ai % x == 0:
cnt += ai // x - 1
else:
cnt += ai // x
# print('check', x, cnt)
return cnt <= k
lb = 0 # False
ub = max(a) # True
while ub - lb > 1:
mid = (ub + lb) // 2
# print(mid, check(mid))
if check(mid):
ub = mid
else:
lb = mid
print(ub)
|
from heapq import heappush, heappop, heapify
n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
def check(x):
# 最長の丸太をx以下にできるか
# 任意の丸太をx以下にできるか
cnt = sum([(ai - 1) // x for ai in a])
return cnt <= k
lb = 0 # False
ub = max(a) # True
while ub - lb > 1:
mid = (ub + lb) // 2
# print(mid, check(mid))
if check(mid):
ub = mid
else:
lb = mid
print(ub)
|
p02598
|
import heapq
import math
n, k = list(map(int, input().split()))
A = list(map(int, input().split()))
H = []
for i in range(n):
heapq.heappush(H, (-A[i], 1))
for i in range(k):
int, num = heapq.heappop(H)
heapq.heappush(H, (int*num/(num+1), num+1) )
print((math.ceil(-H[0][0])))
|
import math
n, k = list(map(int, input().split()))
A = list(map(int, input().split()))
l = 1
r = 10**9+1
while l < r:
mid = (l+r)//2
count = 0
for i in range(n):
if A[i] > mid:
count += math.ceil(A[i]//mid)
if count <= k:
r = mid
else:
l = mid+1
print(l)
|
p02598
|
import math
n, k = list(map(int, input().split()))
A = list(map(int, input().split()))
l = 1
r = 10**9+1
while l < r:
mid = (l+r)//2
count = 0
for i in range(n):
if A[i] > mid:
count += math.ceil(A[i]/mid-1)
if count <= k:
r = mid
else:
l = mid+1
print(l)
|
n, k = list(map(int, input().split()))
A = list(map(int, input().split()))
l = 1
r = 10**9+1
while l < r:
mid = (l+r)//2
count = 0
for i in range(n):
if A[i] > mid:
count += A[i]//mid
if count <= k:
r = mid
else:
l = mid+1
print(l)
|
p02598
|
import heapq
ceil = lambda a, b: (a + b - 1) // b
N, K = list(map(int, input().split()))
A = tuple(map(int, input().split()))
h = [(-a, a, 1) for a in A]
heapq.heapify(h)
for _ in range(K):
l, a, ct = heapq.heappop(h)
ct += 1
heapq.heappush(h, (-a / ct, a, ct))
_, a, ct = heapq.heappop(h)
print((ceil(a, ct)))
|
ceil = lambda a, b: (a + b - 1) // b
N, K = list(map(int, input().split()))
A = tuple(map(int, input().split()))
# bisect
l, r = 0, max(A)
while r - l > 1:
m = (l + r) // 2
if sum(ceil(x, m) - 1 for x in A) > K:
l = m
else:
r = m
print(r)
|
p02598
|
import math
N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
Z = []
for i in range(N):
ver = [A[i], 0]
Z.append(ver)
for k in range(K):
h = Z.index(max(Z))
Z[h][1] += 1
Z[h][0] /= 2
for j in range(N):
A[j] = A[j]/(Z[j][1]+1)
print((math.ceil(max(A))))
|
import math
N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
def ink(L):
cnt = 0
for i in range(N):
cnt += A[i]//L
if A[i]%L != 0:
cnt += 1
cnt -= 1
return cnt <= K
bottom, top = 0, max(A)
while(top - bottom > 1):
middle = (top + bottom) // 2
if ink(middle): top = middle
else: bottom = middle
print(top)
|
p02598
|
def main():
from math import ceil
N, K = list(map(int, input().split()))
*A, = list(map(int, input().split()))
def binary_search(*, ok, ng, func):
for _ in range(80):
mid = (ok + ng) / 2
if func(mid):
ok = mid
else:
ng = mid
return ok
def is_ok(mid):
cnt = 0
for x in A:
cnt += x // mid
if x % mid == 0:
cnt -= 1
return cnt <= K
ma = max(A)
res = binary_search(ok=ma, ng=0, func=is_ok)
print((ceil(res)))
if __name__ == '__main__':
main()
|
def main():
from math import ceil
N, K = list(map(int, input().split()))
*A, = list(map(int, input().split()))
def binary_search(*, ok, ng, func):
for _ in range(60):
mid = (ok + ng) / 2
if func(mid):
ok = mid
else:
ng = mid
return ok
def is_ok(mid):
cnt = 0
for x in A:
q, r = divmod(x, mid)
cnt += q
if r == 0:
cnt -= 1
return cnt <= K
ma = max(A)
res = binary_search(ok=ma, ng=0, func=is_ok)
print((ceil(res)))
if __name__ == '__main__':
main()
|
p02598
|
from heapq import heapify,heappop,heappush
from math import ceil
def solve(A,N,K):
ans_max,ans_min = max(A),1
while True:
if cutable(A,N,K,(ans_max+ans_min)//2):
if ans_max > (ans_max+ans_min)//2:
ans_max = (ans_max+ans_min)//2
else:
return ans_max
else:
if ans_min < (ans_max+ans_min)//2:
ans_min = (ans_max+ans_min)//2
else:
return ans_max
def cutable(A,N,K,div):
#K回までの切断で全部を長さdiv以下にできるかどうか
cnt = 0
for i in range(N):
cnt += A[i]//div
if A[i] % div == 0:
cnt -= 1
if cnt > K:
return False
return True
def main():
N,K = list(map(int,input().split()))
A = list(map(int,input().split()))
ans = solve(A,N,K)
print(ans)
if __name__ == "__main__":
main()
|
from heapq import heapify,heappop,heappush
def solve(A,N,K):
ans_max,ans_min = max(A),1
while True:
if cutable(A,N,K,(ans_max+ans_min)//2):
if ans_max > (ans_max+ans_min)//2:
ans_max = (ans_max+ans_min)//2
else:
return ans_max
else:
if ans_min < (ans_max+ans_min)//2:
ans_min = (ans_max+ans_min)//2
else:
return ans_max
def cutable(A,N,K,div):
#K回までの切断で全部を長さdiv以下にできるかどうか
cnt = 0
for i in range(N):
cnt += A[i]//div
if A[i] % div == 0:
cnt -= 1
if cnt > K:
return False
return True
def main():
N,K = list(map(int,input().split()))
A = list(map(int,input().split()))
ans = solve(A,N,K)
print(ans)
if __name__ == "__main__":
main()
|
p02598
|
N, K = list(map(int, input().split()))
tree = list(map(int, input().split()))
left = 0
right = 2*(10**9)
treeLen = len(tree)
while right - left > 1:
cnt = 0
mid = (right + left) // 2
for i in range(treeLen):
cnt += tree[i] // mid
if tree[i] % mid == 0:
cnt -= 1 # ちょうどに切れるときは切り口が1減る
if K >= cnt:
right = mid
else:
left = mid
print(right)
|
N, K = list(map(int, input().split()))
tree = list(map(int, input().split()))
left = 0
right = max(tree)
while right - left > 1:
cnt = 0
mid = (right + left) // 2
for i in tree:
cnt += i // mid
if i % mid == 0:
cnt -= 1 # ちょうどに切れるときは切り口が1減る
if K >= cnt:
right = mid
else:
left = mid
print(right)
|
p02598
|
n,k=list(map(int,input().split()))
a=list(map(int,input().split()))
ll=0
rr=10**9+1
for _ in range(10**3):
#最も長い丸太がこれになる
ans=(ll+rr)/2.0
cnt=0
for item in a:
if item>ans:
cnt+=((-1*item)//ans)*(-1)-1
if cnt<=k:
rr=ans
else:
ll=ans
print((int((-1*ans//1)*(-1))))
|
n,k=list(map(int,input().split()))
a=list(map(int,input().split()))
ll=0
rr=10**9+1
for _ in range(10**2):
#最も長い丸太がこれになる
ans=(ll+rr)/2.0
cnt=0
for item in a:
if item>ans:
cnt+=((-1*item)//ans)*(-1)-1
if cnt<=k:
rr=ans
else:
ll=ans
print((int((-1*ans//1)*(-1))))
|
p02598
|
n,k = list(map(int,input().split()))
l = list(map(int,input().split()))
# xは求める長さ
def C(x):
num = 0
for i in range(n):
# (a[i]-1)//x 回切る必要がある
num += (l[i]-1)//x
# k回以内に収まるか
return num <= k
lb,ub = 0,max(l)
for i in range(100):
mid = (lb + ub) / 2
# 条件を満たすならxを小さくしていく
if C(mid):
ub = mid
else:
lb = mid
# print(lb,ub)
import math
ans = math.ceil(ub)
print(ans)
|
n,k = list(map(int,input().split()))
l = list(map(int,input().split()))
# xは求める長さ
def C(x):
num = 0
for i in range(n):
# (a[i]-1)//x 回切る必要がある
num += (l[i]-1)//x
# k回以内に収まるか
return num <= k
lb,ub = 0,max(l)
while ub-lb > 1:
mid = (lb + ub + 1) // 2
# 条件を満たすならxを小さくしていく
if C(mid):
ub = mid
else:
lb = mid
# print(lb,ub)
print(ub)
|
p02598
|
n,k = list(map(int,input().split()))
l = list(map(int,input().split()))
# xは求める長さ
def C(x):
num = 0
for i in range(n):
# (a[i]-1)//x 回切る必要がある
num += (l[i]-1)//x
# k回以内に収まるか
return num <= k
lb,ub = 0,max(l)
while ub-lb > 1:
mid = (lb + ub + 1) // 2
# 条件を満たすならxを小さくしていく
if C(mid):
ub = mid
else:
lb = mid
# print(lb,ub)
print(ub)
|
n,k = list(map(int,input().split()))
l = list(map(int,input().split()))
# xは求める長さ
def C(x):
num = 0
for i in range(n):
# (a[i]-1)//x 回切る必要がある
num += (l[i]-1)//x
# k回以内に収まるか
return num <= k
lb,ub = 0,max(l)
while ub-lb > 1:
mid = (lb + ub) // 2
# 条件を満たすならxを小さくしていく
if C(mid):
ub = mid
else:
lb = mid
# print(lb,ub)
print(ub)
|
p02598
|
from math import ceil
# from decimal import Decimal
N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
# N, K = 2*10**5, 1
# A = [10**9]*N
def solve(x):
m = 0
for a in A:
m += a//x - (a%x == 0)
# print(x, m)
return m <= K
A = [a*10**10 for a in A]
ok, ng = max(A), 0
while abs(ok-ng > 1):
mid = (ok+ng)//2
# print(mid)
if solve(mid):
ok = mid
else:
ng = mid
print((-(-mid//10**10)))
|
BIG = 10**10
N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
# N, K = 2*10**5, 2*10**5
# A = [10**9]*N
def solve(x):
m = 0
for a in A:
m += -(-(a//x))
# print(x, m)
return m > K
A = [a*BIG for a in A]
# c = 0
ok, ng = 0, max(A)
while abs(ok-ng) > 1:
mid = (ok+ng)//2
# print(mid)
if solve(mid):
ok = mid
else:
ng = mid
# c += 1
# print(c)
print((-(-ok//BIG)))
|
p02598
|
n,k = list(map(int,input().split()))
a = list(map(int,input().split()))
s = sum(a)
x = [0]*n
y = 0
r = 0
for i in range(n):
y = int(a[i]/s*k)
x[i] = [i, y, a[i]/(y+1), a[i]]
r += y
x.sort(key= lambda val : val[2],reverse=True)
for i in range(k-r):
x[i][1] += 1
ans = 0
for i in range(n):
ans = max(ans, x[i][3]/(x[i][1]+1))
print((int(-(-ans//1))))
|
n,k = list(map(int,input().split()))
a = list(map(int,input().split()))
s = sum(a)
x = [0]*n
t = 0
for i in range(n):
y = int(a[i]/s * k)
x[i] = [i, a[i], y, a[i]/(y+1)]
t += y
x.sort(key= lambda val : val[3],reverse=True)
for i in range(k-t):
x[i][2] += 1
ans = 0
for i in range(n):
ans = max(ans, x[i][1]/(x[i][2]+1))
print((int(-(-ans//1))))
|
p02598
|
#import numpy as np
#import collections
#import math
#f = open('./input_E.txt')
#
#N,K = map(int, f.readline().split())
#A = list(map(int, f.readline().split()))
N,K = list(map(int, input().split()))
A = list(map(int, input().split()))
if K == 0:
ans = max(A)
else:
A.sort(reverse=True)
All_length = sum(A)
KK = K+N-1
lm = All_length/(KK+1)
k_list = [int(Ai//lm) for Ai in A]
X_list = [Ai%lm for Ai in A]
sum_k = sum(k_list)
res_cut = KK-sum_k
zero_k = 0
for i in range(1,N+1):
if k_list[-i] == 0:
zero_k +=1
else:
break
if res_cut > 0:
ans_kouho = []
for i in range(-zero_k,0):
ans_kouho.append(X_list[i])
for i in range(res_cut):
for j in range(N-zero_k):
ans_kouho.append((X_list[j]-i*lm)/k_list[j])
ans_kouho.sort(reverse=True)
ans = ans_kouho[res_cut] + lm
ans = int(ans)+1
else:
ans = int(lm)+1
print(ans)
|
#import numpy as np
#import collections
#import math
#f = open('./input_E.txt')
#
#N,K = map(int, f.readline().split())
#A = list(map(int, f.readline().split()))
N,K = list(map(int, input().split()))
A = list(map(int, input().split()))
A.sort(reverse=True)
def nibu(small,big,KK,AA):
mid = (small+big)//2
k_list = [(x-1)//mid for x in AA]
sum_k = sum(k_list)
if sum_k <= KK: #達成可能 -> 答えはもっと小さい
return small,mid # 不可能,可能
else:
return mid,big # 不可能,可能
if K==0:
ans = A[0]
else:
lmin = 0
lmax = A[0]
while lmax - lmin >= 2:
lmin, lmax = nibu(lmin,lmax,K,A)
ans = lmax
print(ans)
|
p02598
|
def examA():
X = I()
if X<30:
ans = "No"
else:
ans = "Yes"
print(ans)
return
def examB():
N, D = LI()
cnt = 0
for _ in range(N):
x, y = LI()
if x**2+y**2<=D**2:
cnt += 1
ans = cnt
print(ans)
return
def examC():
N = 10**7
K = I()
cur = 0
now = 1
ans = -1
for i in range(N):
cur += 7 * now
cur %= K
if cur==0:
ans = i+1
break
now *= 10
now %= K
print(ans)
return
def examD():
N = I()
C = SI()
cnt = 0
l = 0; r = N-1
while(l<r):
while(l<N):
if C[l]=="W":
break
l += 1
while(0<=r):
if C[r]=="R":
break
r -= 1
if l<r:
cnt += 1
l += 1
r -= 1
ans = cnt
print(ans)
return
def examE():
N, K = LI()
A = LI()
if K==0:
print((max(A)))
return
l = 0; r = inf
for _ in range(80):
now = dec((l+r)/2)
cnt = 0
for a in A:
cur = a//now
cnt += cur
if K<cnt:
l = now
else:
r = now
#print(now,cnt)
#input()
ans = l
if ans - ans//1>0:
ans += 1
ans //=1
#print(now)
print(ans)
return
def examF():
N, Q = LI()
C = LI()
for q in range(Q):
l, r = LI()
ans = [0]*Q
for v in ans:
print(v)
return
from decimal import getcontext,Decimal as dec
import sys,bisect,itertools,heapq,math,random
from copy import deepcopy
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
def I(): return int(eval(input()))
def LI(): return list(map(int,sys.stdin.readline().split()))
def DI(): return dec(eval(input()))
def LDI(): return list(map(dec,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf,alphabet,_ep,alphabet_convert
mod = 10**9 + 7
mod2 = 998244353
inf = dec("20000000000")
_ep = dec("0.000000000001")
alphabet = [chr(ord('a') + i) for i in range(26)]
alphabet_convert = {chr(ord('a') + i): i for i in range(26)}
getcontext().prec = 12
sys.setrecursionlimit(10**7)
if __name__ == '__main__':
examE()
"""
142
12 9 1445 0 1
asd dfg hj o o
aidn
"""
|
def examA():
X = I()
if X<30:
ans = "No"
else:
ans = "Yes"
print(ans)
return
def examB():
N, D = LI()
cnt = 0
for _ in range(N):
x, y = LI()
if x**2+y**2<=D**2:
cnt += 1
ans = cnt
print(ans)
return
def examC():
N = 10**7
K = I()
cur = 0
now = 1
ans = -1
for i in range(N):
cur += 7 * now
cur %= K
if cur==0:
ans = i+1
break
now *= 10
now %= K
print(ans)
return
def examD():
N = I()
C = SI()
cnt = 0
l = 0; r = N-1
while(l<r):
while(l<N):
if C[l]=="W":
break
l += 1
while(0<=r):
if C[r]=="R":
break
r -= 1
if l<r:
cnt += 1
l += 1
r -= 1
ans = cnt
print(ans)
return
def examE():
N, K = LI()
A = LI()
if K==0:
print((max(A)))
return
l = 0; r = inf
while(r-l>1):
now = (l+r)//2
cnt = 0
for a in A:
cur = a//now
if a%now==0:
cur -= 1
cnt += cur
if cnt<=K:
r = now
else:
l = now
#print(now,cnt)
#input()
ans = r
print(ans)
return
def examF():
# 0は絶対に入れない!!
class Bit():
def __init__(self, n):
self.size = n
self.tree = [0] * (n + 1)
return
def sum(self, i):
s = 0
while i > 0:
s += self.tree[i]
i -= i & -i
return s
def add(self, i, x=1):
# i==0 はだめ => 全部+1するとか
while i <= self.size:
self.tree[i] += x
i += i & -i
return
def search(self, x):
# 二分探索。和がx以上となる最小のインデックス(>= 1)を返す
# maspyさんの参考 よくわかってない
i = 0
s = 0
step = 1 << ((self.size).bit_length() - 1)
while step:
if i + step <= self.size and s + self.tree[i + step] < x:
i += step
s += self.tree[i]
step >>= 1
return i + 1
def debug(self, k):
return [self.sum(i) for i in range(k)]
def inversion(self, A=[3, 10, 1, 8, 5]):
res = 0
for i, p in enumerate(A):
self.add(p, 1)
res += i + 1 - self.sum(p)
return res
N, Q = LI()
C = LI()
LR = []
lastAppeared = [-1]*N
for i in range(Q):
l, r = LI()
LR.append((l,r,i))
LR.sort(key=lambda x:x[1])
#print(LR)
bit = Bit(N+1)
ans = [0]*Q
r = 0
now = 0
while(r<N):
if now==Q:
break
l0, r0, i0 = LR[now]
while(r<r0):
c = C[r]-1
if lastAppeared[c]>0:
bit.add(lastAppeared[c],-1)
lastAppeared[c] = r+1
bit.add(lastAppeared[c]+1)
r += 1
#print(bit.debug(r))
while(now<Q):
l0,r0,i0 = LR[now]
if r<r0:
break
#print(r,now)
ans[i0] = bit.sum(r0)
if l0>1:
ans[i0] -= bit.sum(l0-1)
now += 1
for v in ans:
print(v)
return
from decimal import getcontext,Decimal as dec
import sys,bisect,itertools,heapq,math,random
from copy import deepcopy
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
def I(): return int(eval(input()))
def LI(): return list(map(int,sys.stdin.readline().split()))
def DI(): return dec(eval(input()))
def LDI(): return list(map(dec,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf,alphabet,_ep,alphabet_convert
mod = 10**9 + 7
mod2 = 998244353
inf = 1<<60
_ep = dec("0.000000000001")
alphabet = [chr(ord('a') + i) for i in range(26)]
alphabet_convert = {chr(ord('a') + i): i for i in range(26)}
getcontext().prec = 9
sys.setrecursionlimit(10**5)
if __name__ == '__main__':
examE()
"""
142
12 9 1445 0 1
asd dfg hj o o
aidn
"""
|
p02598
|
from heapq import heapify, heappop, heappush
from math import ceil
n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
b = []
for v in a:
b.append([-v, -v, 1])
heapify(b)
for _ in range(k):
x, y, z = heappop(b)
heappush(b, [y/(z+1), y, z+1])
res = heappop(b)
print((ceil(-res[0])))
|
n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
hi = 10 ** 9
lo = 0
while hi - lo > 1:
mid = (hi + lo) // 2
cnt = 0
for v in a:
cnt += (v + mid - 1) // mid - 1
if cnt <= k:
hi = mid
else:
lo = mid
print(hi)
|
p02598
|
n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
hi = 10 ** 9
lo = 0
while hi - lo > 1:
mid = (hi + lo) // 2
cnt = 0
for v in a:
cnt += (v + mid - 1) // mid - 1
if cnt <= k:
hi = mid
else:
lo = mid
print(hi)
|
def binary_search(key):
'''
条件を満たす最小のindexを求める
'''
right = 10 ** 9 + 1
left = 0
while right - left > 1:
mid = (right + left) // 2
cnt = 0
for v in a:
cnt += (v + mid - 1) // mid - 1
if cnt <= key:
right = mid
else:
left = mid
return right
n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
print((binary_search(k)))
|
p02598
|
def binary_search(key):
'''
条件を満たす最小/最大のindexを求める
'''
ok = 10 ** 9 # 条件を満たすindexの上限値/下限値
ng = 0 # 条件を満たさないindexの下限値-1/上限値+1
while abs(ok - ng) > 1:
mid = (ok + ng) // 2
cnt = 0
for v in a:
cnt += (v + mid - 1) // mid - 1
if cnt <= key: # midが条件を満たすか否か
ok = mid
else:
ng = mid
return ok
n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
print((binary_search(k)))
|
# Binary Search
def isOK(i, key):
'''
問題に応じて返り値を設定
'''
cnt = 0
for v in a:
cnt += (v + i - 1) // i - 1
return cnt <= key
def binary_search(key):
'''
条件を満たす最小/最大のindexを求める
O(logN)
'''
ok = 10 ** 9 # 条件を満たすindexの上限値/下限値
ng = 0 # 条件を満たさないindexの下限値-1/上限値+1
while abs(ok - ng) > 1:
mid = (ok + ng) // 2
if isOK(mid, key): # midが条件を満たすか否か
ok = mid
else:
ng = mid
return ok
n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
print((binary_search(k)))
|
p02598
|
import bisect
import copy
import heapq
import math
import sys
from collections import *
from functools import lru_cache
from itertools import accumulate, combinations, permutations, product
def input():
return sys.stdin.readline()[:-1]
def ruiseki(lst):
return [0]+list(accumulate(lst))
sys.setrecursionlimit(500000)
mod=pow(10,9)+7
al=[chr(ord('a') + i) for i in range(26)]
direction=[[1,0],[0,1],[-1,0],[0,-1]]
n,k=list(map(int,input().split()))
a=list(map(int,input().split()))
l,h=0,max(a)
while h-l>0.0000001:
mid=(h+l)/2
# print(l,h,mid)
cnt=0
for i in range(n):
cnt+=math.ceil(a[i]/mid)-1
# print(a[i]/mid)
# print(cnt)
if cnt<=k:
h=mid
else:
l=mid
# print(l)
print((math.ceil(l-0.000001)))
|
import bisect
import copy
import heapq
import math
import sys
from collections import *
from functools import lru_cache
from itertools import accumulate, combinations, permutations, product
def input():
return sys.stdin.readline()[:-1]
def ruiseki(lst):
return [0]+list(accumulate(lst))
sys.setrecursionlimit(500000)
mod=pow(10,9)+7
al=[chr(ord('a') + i) for i in range(26)]
direction=[[1,0],[0,1],[-1,0],[0,-1]]
n,k=list(map(int,input().split()))
a=list(map(int,input().split()))
l,h=0,max(a)
while h-l>1:
mid=(h+l)//2
# print(l,h,mid)
cnt=0
for i in range(n):
cnt+=math.ceil(a[i]/mid)-1
# print(a[i]/mid)
# print(cnt)
if cnt<=k:
h=mid
else:
l=mid
# print(l)
print(h)
|
p02598
|
N, K = list(map(int,input().split()))
A = list(map(int,input().split()))
start = 0
end = max(A)
while end - start > 1:
l = (start + end)/2
l = int(l)
count = 0
for i in range(N):
q = A[i]/l
if q == int(q):
q -= 1
count += int(q)
if count <= K:
end = l
else:
start = l
print(end)
|
N, K = list(map(int,input().split()))
A = list(map(int,input().split()))
start = 0
end = 10**9
while end - start > 1:
l = (start + end)/2
l = int(l)
count = 0
for i in range(N):
q = A[i]/l
if q == int(q):
q -= 1
count += int(q)
if count <= K:
end = l
else:
start = l
print(end)
|
p02598
|
import math
from heapq import heapify, heappop, heappush
LI = lambda: list(map(int, input().split()))
N, K = LI()
A = LI()
def main():
hq = [(-a, -a, 1) for a in A]
heapify(hq)
for _ in range(K):
x = heappop(hq)
t = (x[1] / (x[2] + 1), x[1], x[2] + 1)
heappush(hq, t)
ans = math.ceil(-heappop(hq)[0])
print(ans)
if __name__ == "__main__":
main()
|
import math
LI = lambda: list(map(int, input().split()))
N, K = LI()
A = LI()
def judge(x):
k = 0
for a in A:
if a <= x:
continue
if a % x == 0:
k += a // x - 1
else:
k += a // x
if k <= K:
return True
else:
return False
def solve():
left, right = 0, max(A)
while right - left > 1:
x = (left + right) // 2
if judge(x):
right = x
else:
left = x
return right
def main():
ans = solve()
print(ans)
if __name__ == "__main__":
main()
|
p02598
|
import heapq
import bisect
n,k=list(map(int, input().split()))
A=[int(i) for i in input().split()]
ng=0
ok = max(A)
while(ng+1!=ok):
mid = (ok+ng)//2
ans = 0
for i in A:
ans += 0--i//mid-1
if(ans<=k):
ok = mid
else:
ng = mid
print(ok)
|
n,k=list(map(int, input().split()))
A=[int(i) for i in input().split()]
ng=0
ok = max(A)
while(ng+1!=ok):
mid = (ok+ng)//2
ans = 0
for i in A:
ans += 0--i//mid-1
if(ans<=k):
ok = mid
else:
ng = mid
print(ok)
|
p02598
|
n,k=list(map(int,input().split()))
a=list(map(int,input().split()))
suma=sum(a)
import math
def func(x):
chk=0
for ai in a:
# 長さx以下に分割するなら最小でtmp本にわかれる
tmp=math.ceil(ai/x)
chk+=tmp
return chk<=n+k
l,r=0,max(a)
for _ in range(100):
x=(l+r)/2
if func(x):# k回ですべてx以下にできるなら、もっと小さくできそう
l,r=l,x
else:
l,r=x,r
x=(l+r)/2
print((math.ceil(x)))
#print(l,r,x)
|
n,k=list(map(int,input().split()))
a=list(map(int,input().split()))
suma=sum(a)
import math
def func(x):
chk=0
for ai in a:
# 長さx以下に分割するなら最小でtmp本にわかれる
tmp=math.ceil(ai/x)
chk+=tmp
return chk<=n+k
l,r=0,max(a)
for _ in range(50):
x=(l+r)/2
if func(x):# k回ですべてx以下にできるなら、もっと小さくできそう
l,r=l,x
else:
l,r=x,r
x=(l+r)/2
print((math.ceil(x)))
#print(l,r,x)
|
p02598
|
import math
n,k = list(map(int,input().split()))
a = list(map(int,input().split()))
if k == 0:
print((max(a)))
exit()
suki = 1000000000
kirai = 0
while int(suki) != int(kirai):
targ = (suki+kirai)/2
cnt = 0
mode = 1
for i in range(n):
cnt += math.ceil(a[i] / targ)-1
if cnt > k:
mode = 0
break
if mode:
suki = targ
else:
kirai = targ
print((math.ceil(suki)))
|
import math
n,k = list(map(int,input().split()))
a = list(map(int,input().split()))
if k == 0:
print((max(a)))
exit()
suki = 1000000000
kirai = 0
while int(suki) != int(kirai):
targ = (suki+kirai)/2
cnt = 0
mode = 1
for i in range(n):
cnt += (a[i]-1)//targ
if cnt > k:
mode = 0
break
if mode:
suki = targ
else:
kirai = targ
print((math.ceil(suki)))
|
p02598
|
import sys
readline = sys.stdin.readline
from heapq import *
def solve():
N, K = list(map(int, readline().split()))
A = list(map(int ,readline().split()))
A.sort()
B = [(-a, 1) for a in A]
heapify(B)
for i in range(K):
b, n = heappop(B)
heappush(B, (b * n / (n + 1), n + 1))
ans = -min(B)[0]
if ans != int(ans):
print((int(1 + ans)))
else:
print(ans)
solve()
|
import sys
readline = sys.stdin.readline
N, K = list(map(int, readline().split()))
A = list(map(int, readline().split()))
l = 0
r = 10**10
def test(m):
return sum((a + m - 1) // m for a in A) - N <= K
while l + 1 < r:
m = (l + r) // 2
if test(m):
r = m
else:
l = m
print(r)
|
p02598
|
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return list(map(int, sys.stdin.readline().split()))
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
def dp2(ini, i, j): return [[ini]*i for i2 in range(j)]
#import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value
#from collections import Counter # a = Counter(A).most_common()
from itertools import accumulate #list(accumulate(A))
import math
N, K = mi()
A = li()
if K == 0:
print((max(A)))
exit()
left = 0
right = max(A)
def count(num):
cnt = 0
for i in range(N):
cnt += math.ceil(A[i] / num) - 1
return cnt
while True:
mid = (left + right) // 2
if mid == 0:
print((1))
exit()
tmp = count(mid)
if right - left <= 1:
mid = right
break
elif tmp > K:
left = mid
else:
right = mid
right = mid
while True:
tmp = count(mid)
if tmp == K and tmp != count(mid-1):
print(mid)
break
elif tmp == K:
right = mid
else:
#if left == mid:
#print(mid+1)
#break
left = mid
mid = (left + right) // 2
if mid == 0:
print((1))
break
|
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return list(map(int, sys.stdin.readline().split()))
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
def dp2(ini, i, j): return [[ini]*i for i2 in range(j)]
#import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value
#from collections import Counter # a = Counter(A).most_common()
from itertools import accumulate #list(accumulate(A))
import math
N, K = mi()
A = li()
if K == 0:
print((max(A)))
exit()
left = 0
right = max(A)
def count(num):
cnt = 0
for i in range(N):
cnt += math.ceil(A[i] / num) - 1
return cnt
while True:
mid = (left + right) // 2
if mid == 0:
print((1))
exit()
tmp = count(mid)
if right - left <= 1:
mid = right
break
elif tmp > K:
left = mid
else:
right = mid
right = mid
while True:
tmp = count(mid)
if tmp == K and tmp != count(mid-1):
print(mid)
break
elif tmp == K:
right = mid
else:
if left == mid:
print(right)
break
left = mid
mid = (left + right) // 2
if mid == 0:
print((1))
break
|
p02598
|
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return list(map(int, sys.stdin.readline().split()))
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
def dp2(ini, i, j): return [[ini]*i for i2 in range(j)]
#import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value
#from collections import Counter # a = Counter(A).most_common()
#from itertools import accumulate #list(accumulate(A))
import math
N, K = mi()
A = li()
if K == 0:
print((max(A)))
exit()
left = 0
right = max(A)
def count(num):
cnt = 0
for i in range(N):
cnt += math.ceil(A[i] / num) - 1
return cnt
while True:
mid = (left + right) // 2
if mid == 0:
mid += 1
break
tmp = count(mid)
if tmp == K:
break
elif tmp > K:
if left == mid:
mid = right
break
left = mid
else:
right = mid
if mid == 0 or mid == 1:
print(mid)
exit()
right = mid
while True:
tmp = count(mid)
if tmp == K and tmp != count(mid-1):
print(mid)
break
elif tmp == K:
right = mid
else:
if left == mid:
print(right)
break
left = mid
mid = (left + right) // 2
if mid == 0:
print((1))
break
|
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return list(map(int, sys.stdin.readline().split()))
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
def dp2(ini, i, j): return [[ini]*i for i2 in range(j)]
#import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value
#from collections import Counter # a = Counter(A).most_common()
#from itertools import accumulate #list(accumulate(A))
import math
N, K = mi()
A = li()
if K == 0:
print((max(A)))
exit()
left = 0
right = max(A)
def count(num):
cnt = 0
for i in range(N):
cnt += math.ceil(A[i] / num) - 1
return cnt
while True:
mid = (left + right) // 2
if mid == 0:
print((1))
break
tmp = count(mid)
if right - left <= 1:
print(right)
exit()
elif tmp > K:
left = mid
else:
right = mid
|
p02598
|
#from fractions import Fraction
from math import ceil
from heapq import heappush, heappop
N, K = list(map(int, input().split()))
A_queue = []
for a in input().split():
a = float(a)
heappush(A_queue, (-a, a, 1))
# search smallest i such that f(i) == True
def auto_bisearch_smallest(f, s = None):
if s == None:
s = 0
w = -1
while f(s) == True:
s = w
w *= 2
e = s
w = 1
while f(e) == False:
e = s + w
w *= 2
return bisearch_smallest(f, s, e + 1)
# search smallest i ( s <= i < e ) such that f(i) == True
def bisearch_smallest(f, s, e = None):
if e == None:
e = s - 1
s = 0
else:
e -= 1
while s < e:
m = (s + e) // 2
if f(m):
e = m
else:
s = m + 1
if s == e and f(s):
return s
else:
return -1
def calc(K):
while K > 0:
length, a, div = heappop(A_queue)
if len(A_queue) > 0:
ref = A_queue[0][0]
new_div = auto_bisearch_smallest(lambda div: -a / div > ref, div)
K -= (new_div - div)
heappush(A_queue, (-a / new_div, a, new_div))
else:
div += K
K = 0
heappush(A_queue, (-a / div, a, div))
return -A_queue[0][0]
print((ceil(calc(K))))
|
N, K = list(map(int, input().split()))
A_list = list(map(int, input().split()))
# search smallest i such that f(i) == True
def auto_bisearch_smallest(f, s = None):
if s == None:
s = 0
w = -1
while f(s) == True:
s = w
w *= 2
e = s
w = 1
while f(e) == False:
e = s + w
w *= 2
return bisearch_smallest(f, s, e + 1)
# search smallest i ( s <= i < e ) such that f(i) == True
def bisearch_smallest(f, s, e = None):
if e == None:
e = s - 1
s = 0
else:
e -= 1
while s < e:
m = (s + e) // 2
if f(m):
e = m
else:
s = m + 1
if s == e and f(s):
return s
else:
return -1
def calc(length):
count = 0
for a in A_list:
if a > length:
if a % length == 0:
count += (a // length) - 1
else:
count += a // length
return count
print((auto_bisearch_smallest(lambda length: calc(length) <= K, 1)))
|
p02598
|
import heapq
import math
def resolve():
_,k = list(map(int, input().split()))
A = list(map(int, input().split()))
heap = []
for a in A:
heapq.heappush(heap, (-a, -a, 1))
while k > 0:
a = heapq.heappop(heap)
origin = a[1]
denom = a[2]
denom += 1
new = (origin/denom, origin, denom)
heapq.heappush(heap, new)
k -= 1
a = heapq.heappop(heap)
ans = a[0]*-1
print((math.ceil(ans)))
resolve()
|
import math
def resolve():
_,K = list(map(int, input().split()))
A = list(map(int, input().split()))
start = 0
end = 10**9
while end - start > 1:
cnt = 0
mid = (start + end) // 2
for a in A:
cnt += math.ceil(a/mid) - 1
if cnt <= K:
end = mid
else:
start = mid
print(end)
resolve()
|
p02598
|
import math
N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
# にぶたん! 半開区間二分探索は正義
def calc(x):
count = 0
for a in A:
count += (a - 1) // x
return count <= K
A.sort(reverse=True)
r = 10 ** 9
l = 0
while abs(r - l) > 1:
mid = (r + l) // 2
if calc(mid):
r = mid
else:
l = mid
print(r)
|
import math
N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
# めぐる式二分探索で実装
def calc(x):
count = 0
for a in A:
count += (a - 1) // x
return count <= K
ok = 10 ** 9
ng = 0
while abs(ok - ng) > 1:
mid = (ok + ng) // 2
if calc(mid):
ok = mid
else:
ng = mid
print(ok)
|
p02598
|
from bisect import bisect_left
def main():
N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
A.sort()
def check(x):
index = bisect_left(A,x)
ans = 0
for i in range(index,N):
if A[i] % x == 0:
tmp = (A[i] // x) - 1
else:
tmp = A[i] // x
ans += tmp
if ans <= K:
return True
else:
return False
ok = max(A)
ng = 0
while abs(ok- ng) > 1:
mid = (ok + ng) // 2
if check(mid):
ok = mid
else:
ng = mid
print(ok)
if __name__ == "__main__":
main()
|
from bisect import bisect_left
def main():
N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
A.sort()
def check(x):
index = bisect_left(A,x)
ans = 0
for i in range(index,N):
tmp = -(-A[i] // x) - 1
ans += tmp
if ans <= K:
return True
else:
return False
ok = max(A)
ng = 0
while abs(ok- ng) > 1:
mid = (ok + ng) // 2
if check(mid):
ok = mid
else:
ng = mid
print(ok)
if __name__ == "__main__":
main()
|
p02598
|
# -*- coding: utf-8 -*-
# template: v1.3.1
# 丸太の分割分割問題。
# 速度の観点から、「答えの二分探索」が必要。典型らしい。
import io
import sys
import math
### DEBUG ###
_DEB = 0 # 1:ON / 0:OFF
_INPUT = """\
2 1
1 50
"""
# Worst
# _INPUT = f"{str(2*(10**5))} {str(10**9)}\n{(str(10**9)+' ')*(2*(10**5)) }"
# _INPUT = f"{str(2*(10**5))} {str(10**9)}\n{(str(10**9)+' ')*(2*(10**5)) }"
_EXPECTED = """\
ABC
"""
if _DEB:
sys.stdin = io.StringIO(_INPUT)
print("!! Debug Mode !!")
def logd(str):
if _DEB: print(f"[deb] {str}")
# is_m_OK?
def f(m):
cut=0
for aa in a:
c=math.ceil(aa/m)
cut+=c-1
if cut > k:
return False
return True
#m=7,a=[7,9]
### INPUT ####
n,k = list(map(int, input().split()))
a = list(map(int, input().split()))
### Solve ####
def solve():
# Process
ans=0
l,r=0,10**9
while abs(r-l)!=1:
m=(l+r)//2
if f(m): # m is ok: Go left
r=m
else: # m is ng : Go right
l=m
ans=r
# ans=min(r,max(a))
# OUPUT
ans = str(ans)
print(ans)
return ans
### MAIN ###
if __name__ == "__main__":
ans = solve()
# Checker
if _DEB:
if _EXPECTED.strip() == ans.strip(): print("\n!! Success !!")
else: print(f"\n!! Failed... !!\nANSWER: {ans}\nExpected: {_EXPECTED}")
|
# -*- coding: utf-8 -*-
# template: v1.3.1
# 丸太の分割分割問題。
# 速度の観点から、「答えの二分探索」が必要。典型らしい。
# f(x) の処理、すぬけさんのをチェック
import io
import sys
import math
### DEBUG ###
_DEB = 0 # 1:ON / 0:OFF
_INPUT = """\
2 1
1 3
"""
# Worst
# _INPUT = f"{str(2*(10**5))} {str(10**9)}\n{(str(10**9)+' ')*(2*(10**5)) }"
# _INPUT = f"{str(2*(10**5))} {str(10**9)}\n{(str(10**9)+' ')*(2*(10**5)) }"
_EXPECTED = """\
ABC
"""
if _DEB:
sys.stdin = io.StringIO(_INPUT)
print("!! Debug Mode !!")
def logd(str):
if _DEB: print(f"[deb] {str}")
# is_m_OK?
def f(m):
cut=0
for aa in a:
#ここを変えた
c=(aa-1)//m
cut+=c
if cut > k:
return False
return True
#m=7,a=[7,9]
### INPUT ####
n,k = list(map(int, input().split()))
a = list(map(int, input().split()))
### Solve ####
def solve():
# Process
ans=0
l,r=0,10**9
while abs(r-l)!=1:
m=(l+r)//2
if f(m): # m is ok: Go left
r=m
else: # m is ng : Go right
l=m
ans=r
# ans=min(r,max(a))
# OUPUT
ans = str(ans)
print(ans)
return ans
### MAIN ###
if __name__ == "__main__":
ans = solve()
# Checker
if _DEB:
if _EXPECTED.strip() == ans.strip(): print("\n!! Success !!")
else: print(f"\n!! Failed... !!\nANSWER: {ans}\nExpected: {_EXPECTED}")
|
p02598
|
import heapq
from math import ceil,floor
import sys
class Fraction():
##入力定義
def __init__(self,Numerator=0,Denominator=1):
"""分数のオブジェクトを生成する.
Numerator:分子
Denominator:分母
"""
self.a=Numerator
self.b=Denominator
#表示定義
def __str__(self):
if self.b==1:
return str(self.a)
else:
return "{}/{}".format(self.a,self.b)
#四則演算定義
def __add__(self,other):
c=Fraction()
if not(isinstance(other,Fraction)):
other=Fraction.Int_to_Fraction(other)
c.a=self.a*other.b+self.b*other.a
c.b=self.b*other.b
return Fraction.__reduce(c)
def __radd__(self,other):
c=Fraction()
if not(isinstance(other,Fraction)):
other=Fraction.Int_to_Fraction(other)
c.a=self.a*other.b+self.b*other.a
c.b=self.b*other.b
return Fraction.__reduce(c)
def __sub__(self,other):
return self+(-other)
def __rsub__(self,other):
return -self+other
def __mul__(self,other):
if not(isinstance(other,Fraction)):
other=Fraction.Int_to_Fraction(other)
return Fraction.__reduce(Fraction(self.a*other.a,self.b*other.b))
def __rmul__(self,other):
if not(isinstance(other,Fraction)):
other=Fraction.Int_to_Fraction(other)
return Fraction.__reduce(Fraction(self.a*other.a,self.b*other.b))
def __floordiv__(self,other):
if other==Fraction():
raise ZeroDivisionError
H=self/other
return H.a//H.b
def __rfloordiv__(self,other):
if self==Fraction():
raise ZeroDivisionError
H=other/self
return H.a//H.b
def __truediv__(self,other):
if other==Fraction():
raise ZeroDivisionError
if not(isinstance(other,Fraction)):
other=Fraction.Int_to_Fraction(other)
return self*Fraction.__inverse(other)
def __rtruediv__(self,other):
if self==Fraction():
raise ZeroDivisionError
if not(isinstance(self,Fraction)):
self=Fraction.Int_to_Fraction(other)
return Fraction.__inverse(self)*other
def __pow__(self,other):
if other==0:
return 1
n=abs(other)
g=1
k=self
for i in range(int(math.log(n,2))+1):
if n%2==1:
g*=k
k*=k
n=n>>1
if other>0:
return g
else:
return 1/g
#丸め
def __floor__(self):
return self.a//self.b
def __ceil__(self):
return (self.a+self.b-1)//self.b
#比較演算子
def __eq__(self,other):
t=self-other
if isinstance(t,Fraction):
return t.a==0
else:
return t==0
def __nq(self,other):
return not(self==other)
def __lt__(self,other):
t=self-other
if isinstance(t,Fraction):
return t.a<0
else:
return t<0
def __le__(self,other):
return (self<other) or (self==other)
def __gt__(self,other):
return -self<-other
def __ge__(self,other):
return (other<self) or (self==other)
#その他
def ToNumber(self):
return self.a/self.b
def sign(self):
s=self.a*self.b
if s>0:return 1
elif s==0:return 0
else:return -1
def __reduce(self):
from math import gcd
g=gcd(self.a,self.b)
self.a//=g
self.b//=g
if self.b<0:
self.a*=-1
self.b*=-1
return Fraction(self.a,self.b)
def Int_to_Fraction(self):
if not(isinstance(self,Fraction)):
return Fraction(self,1)
else:return self
def __inverse(self):
if self==Fraction():
raise ZeroDivisionError
return Fraction.__reduce(Fraction(self.b,self.a))
def __pos__(self):
return self
def __neg__(self):
return Fraction(-self.a,self.b)
def __abs__(self):
return max(self,-self)
#=======================================
N,K=list(map(int,input().split()))
A=list([-Fraction(int(x),1) for x in input().split()])
if N==1:
print(((-A[0]+K)//(K+1)))
sys.exit()
heapq.heapify(A)
while K>0:
x=-heapq.heappop(A)
if x<=1:
heapq.heappush(A,-x)
break
y=-heapq.heappop(A)
r=min(y,(x.a-1)//x.b)
M=min(ceil((x*x.b)/r-x.b),K)
x.b+=M
K-=M
heapq.heappush(A,-x)
heapq.heappush(A,-y)
b=-A[0]
b=ceil(b)
print(b)
|
def BC(A,K):
"""2分探索によって,x未満の要素の個数を調べる.
A:リスト
x:調べる要素
sort:ソートをする必要があるかどうか(Trueで必要)
equal:Trueのときはx"未満"がx"以下"になる
"""
N=max(A)+1
L,R=0,N
while R-L>1:
C=L+(R-L)//2
M=0
for a in A:
M+=(a+C-1)//C-1
if M<=K:
R=C
else:
L=C
return R
N,K=list(map(int,input().split()))
A=list(map(int,input().split()))
print((BC(A,K)))
|
p02598
|
from bisect import bisect_right
from math import ceil
N,K=list(map(int, input().split()))
A=list(map(int, input().split()))
if K==0:
print((max(A)))
exit()
A=sorted(A)
# 最小値で二分探索 してまだ行けるかどうか
# 回数で二分探索
left=0
right=max(A)
ans=float("INF")
pre=ans
flag=False
count=0
while True:
now=0
mid=(left+right)/2
idx=bisect_right(A, mid)
for i in range(idx, N):
now+=ceil(A[i]/mid)-1
if now==K:
if ans!=float("INF"):
if ans==ceil(mid):
flag=True
ans=min(ans, ceil(mid))
right=mid
#if flag:
# break
pre=ans
if now>K:
left=mid
pre=mid
if now<K:
ans=min(ans, ceil(mid))
right=mid
pre=mid
count+=1
if count>=10**3:
break
if ans==float("INF"):
ans=max(A)
print((ceil(ans)))
|
from bisect import bisect_right
from math import ceil
N,K=list(map(int, input().split()))
A=list(map(int, input().split()))
if K==0:
print((max(A)))
exit()
A=sorted(A)
# 最小値で二分探索 してまだ行けるかどうか
# 回数で二分探索
left=0
right=max(A)
ans=float("INF")
pre=ans
flag=False
count=0
while True:
now=0
mid=(left+right)/2
idx=bisect_right(A, mid)
for i in range(idx, N):
now+=ceil(A[i]/mid)-1
if now==K:
if ans!=float("INF"):
if ans==ceil(mid):
flag=True
ans=min(ans, ceil(mid))
right=mid
#if flag:
# break
pre=ans
if now>K:
left=mid
pre=mid
if now<K:
ans=min(ans, ceil(mid))
right=mid
pre=mid
count+=1
if count>=10**2:
break
if ans==float("INF"):
ans=max(A)
print((ceil(ans)))
|
p02598
|
from bisect import bisect_right
from math import ceil
N,K=list(map(int, input().split()))
A=list(map(int, input().split()))
if K==0:
print((max(A)))
exit()
A=sorted(A)
# 最小値で二分探索 してまだ行けるかどうか
# 回数で二分探索
left=0
right=max(A)
ans=float("INF")
pre=ans
flag=False
count=0
while True:
now=0
mid=(left+right)/2
idx=bisect_right(A, mid)
for i in range(idx, N):
now+=ceil(A[i]/mid)-1
if now==K:
if ans!=float("INF"):
if ans==ceil(mid):
flag=True
ans=min(ans, ceil(mid))
right=mid
#if flag:
# break
pre=ans
if now>K:
left=mid
pre=mid
if now<K:
ans=min(ans, ceil(mid))
right=mid
pre=mid
count+=1
if count>=10**2:
break
if ans==float("INF"):
ans=max(A)
print((ceil(ans)))
|
from math import ceil
N,K=list(map(int, input().split()))
A=list(map(int, input().split()))
left=1
right=10**9+1
ans=float("INF")
while True:
mid=(left+right)//2
now=0
for i in range(N):
now+=ceil(A[i]/mid)-1
if now>K:
if left==mid:
break
left=mid
else:
ans=min(ans, mid)
if right==mid:
break
right=mid
print(ans)
|
p02598
|
n,k = list(map(int,input().split()))
A = list(map(int,input().split()))
left = 0
right = max(A)
#if accumulate[(ai-1)//k]<=k return True?
def is_ok(x):
cnt = 0
for i in range(n):
cnt += (A[i]-1)//x
return cnt<=k
#binary search
while (right-left)>1:
mid = (left+right)//2
if is_ok(mid):
right = mid
else:
left = mid
print(right)
|
n,k = list(map(int,input().split()))
A = list(map(int,input().split()))
def is_ok(s):
cnt = 0
for i in range(n):
cnt += (A[i]-1)//s
return cnt<=k
def main():
left = 0
right = max(A)
while (right-left)>1:
mid = (right+left)//2
if is_ok(mid):
right = mid
else:
left = mid
return right
print((main()))
|
p02598
|
n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
def check(l):
cnt = 0
for i in range(n):
cnt += a[i] // mid
if a[i] % mid != 0:
cnt += 1
cnt -= 1
return cnt <= k
lb, ub = 0, max(a)
while ub - lb > 1:
mid = (ub + lb) // 2
if check(mid):
ub = mid
else:
lb = mid
print(ub)
|
n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
def check(l):
cnt = 0
for L in a:
cnt += L // mid
if L % mid != 0:
cnt += 1
cnt -= 1
return cnt <= k
lb, ub = 0, max(a)
while ub - lb > 1:
mid = (ub + lb) // 2
if check(mid):
ub = mid
else:
lb = mid
print(ub)
|
p02598
|
from math import ceil
def main():
N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
def is_ok(arg):
# 条件を満たすかどうか?問題ごとに定義
B = [int(ceil(a/arg))-1 for a in A]
#print(arg, B)
if sum(B) <= K:
return True
else:
return False
def meguru_bisect(ng, ok):
'''
初期値のng,okを受け取り,is_okを満たす最小(最大)のokを返す
まずis_okを定義すべし
ng ok は とり得る最小の値-1 とり得る最大の値+1
最大最小が逆の場合はよしなにひっくり返す
'''
while (abs(ok - ng) > 1):
mid = (ok + ng) // 2
if is_ok(mid):
ok = mid
else:
ng = mid
return ok
ans = meguru_bisect(0, int(1e100))
print(ans)
if __name__ == "__main__":
main()
|
from math import ceil
def main():
N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
def is_ok(arg):
# 条件を満たすかどうか?問題ごとに定義
B = [int(ceil(a/arg))-1 for a in A]
#print(arg, B)
if sum(B) <= K:
return True
else:
return False
def meguru_bisect(ng, ok):
'''
初期値のng,okを受け取り,is_okを満たす最小(最大)のokを返す
まずis_okを定義すべし
ng ok は とり得る最小の値-1 とり得る最大の値+1
最大最小が逆の場合はよしなにひっくり返す
'''
while (abs(ok - ng) > 1):
mid = (ok + ng) // 2
if is_ok(mid):
ok = mid
else:
ng = mid
return ok
ans = meguru_bisect(0, int(1e20))
print(ans)
if __name__ == "__main__":
main()
|
p02598
|
import sys
import heapq
import math
def input(): return sys.stdin.readline().rstrip()
def main():
n, k = list(map(int,input().split()))
A = list(map(int,input().split()))
def is_good(mid, key):
kk = 0
for a in A:
kk += -(-a//mid)-1
if kk <= key:
return True
else:
return False
def bi_search(bad, good, key):
while good - bad > 1:
mid = (bad + good)//2
if is_good(mid, key):
good = mid
else:
bad = mid
return good
print((bi_search(0, max(A), k)))
if __name__=='__main__':
main()
|
import sys
import heapq
import math
def input(): return sys.stdin.readline().rstrip()
def main():
n, k = list(map(int,input().split()))
A = list(map(int,input().split()))
def is_good(mid, key):
kk = 0
for a in A:
kk += -(-a//mid)-1
if kk <= key:
return True
else:
return False
def bi_search(bad, good, key):
while good - bad > 1:
mid = (bad + good)//2
if is_good(mid, key):
good = mid
else:
bad = mid
return good
print((bi_search(0, 1000000000, k)))
if __name__=='__main__':
main()
|
p02598
|
import math
N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
def check(k):
cnt = 0
for a in A:
cnt += math.ceil(a/k) - 1
return cnt <= K
l, r = 0, 10**30
while r - l > 1:
mid = (r + l) // 2
if check(mid):
r = mid
else:
l = mid
print(r)
|
import math
N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
def check(k):
cnt = 0
for a in A:
cnt += math.ceil(a/k) - 1
return cnt <= K
l, r = 0, 10**10
while r - l > 1:
mid = (r + l) // 2
if check(mid):
r = mid
else:
l = mid
print(r)
|
p02598
|
#!/usr/bin/env python3
# N,M = map(int,sys.stdin.readline().split())
# a = tuple(map(int,sys.stdin.readline().split())) # single line with multi param
# a = tuple(int(sys.stdin.readline()) for _ in range(N)) # multi line with single param
# a = tuple(tuple(map(int,sys.stdin.readline().rstrip().split())) for _ in range(N)) # multi line with multi param
# s = sys.stdin.readline().rstrip()
# N = int(sys.stdin.readline())
INF = float("inf")
import sys,collections,heapq,math
N,K = list(map(int,sys.stdin.readline().split()))
a = [[-b,b,1] for b in tuple(map(int,sys.stdin.readline().split()))] # single line with multi param
heapq.heapify(a)# a == [1,2,3]
for _ in range(K):
_,ori,di = heapq.heappop(a)
heapq.heappush(a, [-(ori)/(di+1),ori,di+1])
#print(a[0][0])
print((math.ceil(-a[0][0])))
# e = heapq.heappop(a) # e == 1
# heapq.heappush(a, 1) # a == [1,3,2]
# e = heqpq.heappushpop(a,4) # e == 1,a==[2,3,4]
|
#!/usr/bin/env python3
# N,M = map(int,sys.stdin.readline().split())
# a = tuple(map(int,sys.stdin.readline().split())) # single line with multi param
# a = tuple(int(sys.stdin.readline()) for _ in range(N)) # multi line with single param
# a = tuple(tuple(map(int,sys.stdin.readline().rstrip().split())) for _ in range(N)) # multi line with multi param
# s = sys.stdin.readline().rstrip()
# N = int(sys.stdin.readline())
INF = float("inf")
import sys,collections,heapq,math
N,K = list(map(int,sys.stdin.readline().split()))
a = list(map(int,sys.stdin.readline().split())) # single line with multi param
a.sort(reverse=True)
ng = 0
ok = a[0]
def isOK(v):
# within range
# return key <= a[index]
k = K
i = 0
while k >= 0 and i < N:
#print("?",v,i,a[i],k,math.ceil(a[i] / v) -1,k - (math.ceil(a[i]/v) - 1))
k = k - (math.ceil(a[i]/v) - 1)
i += 1
return k >= 0
while abs(ng-ok) > 1:
mid = (ok+ng)//2
#print(mid,isOK(mid))
if isOK(mid):#ok condition?
ok = mid #move ok
else:
ng = mid
#294924427
print((math.ceil(ok)))
# a = [[-b,b,1] for b in tuple(map(int,sys.stdin.readline().split()))] # single line with multi param
# heapq.heapify(a)# a == [1,2,3]
# for _ in range(K):
# _,ori,di = heapq.heappop(a)
# heapq.heappush(a, [-(ori)/(di+1),ori,di+1])
# print(math.ceil(-a[0][0]))
|
p02598
|
N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
A.sort(reverse=True)
def isfeasible(L):
k = 0
for a in A:
if a < L:
break
if a%L == 0:
dk = a//L - 1
else:
dk = a//L
k += dk
if k > K:
return False
return True
l = 0
r = A[0]
while r-l>1:
L = (r+l)//2
if isfeasible(L):
r = L
else:
l = L
print(r)
|
# 解答
N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
A.sort(reverse=True)
def check(L):
count = 0
for a in A:
if a <= L:
break
count += (a-1)//L
if count > K:
return False
return True
l = 0
r = A[0]
while r-l > 1:
c = (r+l)//2
if check(c):
r = c
else:
l = c
print(r)
|
p02598
|
#
import sys
from math import ceil
input=sys.stdin.readline
def main():
N,K=list(map(int,input().split()))
A=list(map(int,input().split()))
aveA=sum(A)/N
K_i=[int(A[i]/aveA*K/N) for i in range(N)]
dA=[A[i]/(K_i[i]+1) for i in range(N)]
res=K-sum(K_i)
for i in range(res):
maxi=dA.index(max(dA))
K_i[maxi]+=1
dA[maxi]=A[maxi]/(K_i[maxi]+1)
maxi=dA.index(max(dA))
print((ceil(A[maxi]/(K_i[maxi]+1))))
if __name__=="__main__":
main()
|
#
import sys
from math import ceil
input=sys.stdin.readline
def main():
N,K=list(map(int,input().split()))
A=list(map(int,input().split()))
aveA=sum(A)/N
d=K/N
K_i=[int(A[i]/aveA*d) for i in range(N)]
dA=[A[i]/(K_i[i]+1) for i in range(N)]
res=K-sum(K_i)
b=[]
for i in range(N):
b.append([dA[i],i])
b.sort(reverse=True)
now=0
for i in range(res):
K_i[b[now][1]]+=1
dA[b[now][1]]=A[b[now][1]]/(K_i[b[now][1]]+1)
if dA[b[now][1]]<b[now+1][0]:
now+=1
maxi=dA.index(max(dA))
print((ceil(A[maxi]/(K_i[maxi]+1))))
if __name__=="__main__":
main()
|
p02598
|
#
import sys
from math import ceil
input=sys.stdin.readline
def main():
N,K=list(map(int,input().split()))
A=list(map(int,input().split()))
K_i=[int(A[i]/sum(A)*(K+N)-1) for i in range(N)]
dA=[A[i]/(K_i[i]+1) for i in range(N)]
res=K-sum(K_i)
b=[]
for i in range(N):
b.append([dA[i],i])
b.sort(reverse=True)
now=0
for i in range(res):
K_i[b[now][1]]+=1
dA[b[now][1]]=A[b[now][1]]/(K_i[b[now][1]]+1)
if dA[b[now][1]]<b[now+1][0]:
now+=1
maxi=dA.index(max(dA))
print((ceil(A[maxi]/(K_i[maxi]+1))))
if __name__=="__main__":
main()
|
#
import sys
from math import ceil
input=sys.stdin.readline
def main():
N,K=list(map(int,input().split()))
A=list(map(int,input().split()))
sumA=sum(A)
K_i=[int(A[i]/sumA*(K+N)-1) for i in range(N)]
dA=[A[i]/(K_i[i]+1) for i in range(N)]
res=K-sum(K_i)
b=[]
for i in range(N):
b.append([dA[i],i])
b.sort(reverse=True)
now=0
for i in range(res):
K_i[b[now][1]]+=1
dA[b[now][1]]=A[b[now][1]]/(K_i[b[now][1]]+1)
if dA[b[now][1]]<b[now+1][0]:
now+=1
maxi=dA.index(max(dA))
print((ceil(A[maxi]/(K_i[maxi]+1))))
if __name__=="__main__":
main()
|
p02598
|
import heapq
N,K = [int(i) for i in input().split()]
A = [[-int(i),int(i),0] for i in input().split()]
heapq.heapify(A)
for _ in range(K):
a = heapq.heappop(A)
a[2] += 1
a[0] = -(a[1]//(a[2]+1))-1
heapq.heappush(A, a)
print((-A[0][0]))
|
N,K = [int(i) for i in input().split()]
A = [int(i) for i in input().split()]
M = max(A)
m = 1
mid = (M+1)//2
while m<M:
n = 0
for a in A:
n += -(-a//mid)-1
if n > K:
m = mid+1
break
else:
M = mid
mid = (M+m)//2
print(mid)
|
p02598
|
# でつoO(YOU PLAY WITH THE CARDS YOU'RE DEALT..)
import sys
from math import ceil
def main(N, K, A):
def cut_times(longest):
return sum(a // longest for a in A if a > longest)
under = 0
r = 10**9
for i in range(100):
m = (under + r) / 2
if cut_times(m) > K: under = m
else: r = m
print((ceil(r - 10**-10)))
if __name__ == '__main__':
input = sys.stdin.readline
N, K = list(map(int, input().split()))
*A, = list(map(int, input().split()))
main(N, K, A)
|
# でつoO(YOU PLAY WITH THE CARDS YOU'RE DEALT..)
import sys
def main(N, K, A):
lo = 0
hi = 10**9
while hi - lo > 1:
m = (lo + hi) // 2
if sum((a + m - 1) // m - 1 for a in A) <= K: hi = m
else: lo = m
print(hi)
if __name__ == '__main__':
input = sys.stdin.readline
N, K = list(map(int, input().split()))
*A, = list(map(int, input().split()))
main(N, K, A)
|
p02598
|
n,k=list(map(int,input().split()))
alst=list([int(x)*100 for x in input().split()])
ok=max(alst)
ng=0
while abs(ok-ng)>1:
cen=(ok+ng)//2
cnt=0
for a in alst:
cnt+=(a+cen-1)//cen-1
if cnt<=k:
ok=cen
else:
ng=cen+1
if ok%100==0:
print((ok//100))
else:
print((ok//100+1))
|
n,k=list(map(int,input().split()))
alst=list(map(int,input().split()))
ok=max(alst)
ng=0
while abs(ok-ng)>1:
cen=(ok+ng)//2
cnt=0
for a in alst:
cnt+=(a+cen-1)//cen-1
if cnt<=k:
ok=cen
else:
ng=cen
print(ok)
|
p02598
|
def is_good(mid, key):
return sum(count_cuts(a, mid) for a in A) <= key
def binary_search(key):
bad, good = 0, 10 ** 16
while good - bad > 1:
mid = (bad + good) // 2
if is_good(mid, key):
good = mid
else:
bad = mid
return good
def count_cuts(a, unit):
return (a + unit - 1) // unit - 1
N, K, *A = list(map(int, open(0).read().split()))
print((binary_search(K)))
|
def is_good(mid, key):
return sum(count_cuts(a, mid) for a in A) <= key
def binary_search(key):
bad, good = 0, 2 * 10 ** 14 + 1
while good - bad > 1:
mid = (bad + good) // 2
if is_good(mid, key):
good = mid
else:
bad = mid
return good
def count_cuts(a, unit):
return (a + unit - 1) // unit - 1
N, K, *A = list(map(int, open(0).read().split()))
print((binary_search(K)))
|
p02598
|
def is_good(mid, key):
return sum(count_cuts(a, mid) for a in A) <= key
def binary_search(key):
bad, good = 0, 2 * 10 ** 14 + 1
while good - bad > 1:
mid = (bad + good) // 2
if is_good(mid, key):
good = mid
else:
bad = mid
return good
def count_cuts(a, unit):
return (a + unit - 1) // unit - 1
N, K, *A = list(map(int, open(0).read().split()))
print((binary_search(K)))
|
def count_cuts(a, unit):
return (a + unit - 1) // unit - 1
def is_good(mid, key):
return sum(count_cuts(a, mid) for a in A) <= key
def binary_search(key):
bad, good = 0, 1_000_000_000
while good - bad > 1:
mid = (bad + good) // 2
if is_good(mid, key):
good = mid
else:
bad = mid
return good
N, K, *A = list(map(int, open(0).read().split()))
print((binary_search(K)))
|
p02598
|
def count_cuts(a, unit):
return (a + unit - 1) // unit - 1
def is_good(mid, key):
return sum(count_cuts(a, mid) for a in A) <= key
def binary_search(key):
bad, good = 0, 1_000_000_000
while good - bad > 1:
mid = (bad + good) // 2
if is_good(mid, key):
good = mid
else:
bad = mid
return good
N, K, *A = list(map(int, open(0).read().split()))
print((binary_search(K)))
|
def is_good(mid, key):
res = 0
for a in A:
res += (a + mid - 1) // mid
return res - N <= key
def binary_search(bad, good, key):
while good - bad > 1:
mid = (bad + good) // 2
if is_good(mid, key):
good = mid
else:
bad = mid
return good
N, K, *A = list(map(int, open(0).read().split()))
print((binary_search(0, 1_000_000_000, K)))
|
p02598
|
import math
n,k=list(map(int,input().split()))
a=sorted(list(map(int,input().split())))
l,r=0,a[-1]
while math.ceil(r)>math.ceil(l):
x=(l+r)/2
cnt=0
for i in a:
if i%x==0:
cnt+=i//x-1
else:
cnt+=i//x
if cnt>k:
l=x
else:
r=x
print((math.ceil(l)))
|
def resolve():
import sys
input = sys.stdin.readline
import math
n,k=list(map(int,input().split()))
a=sorted(list(map(int,input().split())))
l,r=0,a[-1]
while math.ceil(r)>math.ceil(l):
x=(l+r)/2
cnt=0
for i in a:
if i%x==0:
cnt+=i//x-1
else:
cnt+=i//x
if cnt>k:
l=x
else:
r=x
print((math.ceil(l)))
if __name__ == '__main__':
resolve()
|
p02598
|
from heapq import heappush, heappop, heapify
import math
def solve():
n , k= list(map(int, input().strip().split()))
# if k >= 10*8:
# return 1
a= [(-int(x),1,int(x)) for x in input().strip().split()]
heapify(a)
for i in range(k):
x,cnt,orig = heappop(a)
heappush(a,(-((orig+cnt)//(cnt+1)),cnt+1,orig))
return -(heappop(a)[0])
print((solve()))
|
from heapq import heappush, heappop, heapify
import math
def check(a,mid,k):
cnt = 0
for x in a:
cur_cnt = (x+mid-1)//mid - 1
cnt+=cur_cnt
if cnt > k:
return False
return True
def solve():
n , k= list(map(int, input().strip().split()))
a= [int(x) for x in input().strip().split()]
l = 0
r = 10**9+20
while r-l > 1:
mid = (r+l)//2
if check(a,mid,k):
r = mid
else:
l = mid
return l+1
print((solve()))
|
p02598
|
N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
l = 0
r = max(A)
for _ in range(100):
mid = (r + l + 1) // 2
count = 0
for log in A:
if log > mid:
count += (log + mid - 1) // mid - 1
if count <= K:
r = mid
else:
l = mid
print(r)
|
N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
l = 0
r = max(A)
for _ in range(30):
mid = (r + l + 1) // 2
count = 0
for log in A:
if log > mid:
count += (log + mid - 1) // mid - 1
if count <= K:
r = mid
else:
l = mid
print(r)
|
p02598
|
#各丸太を何回切るか、どこで切るか
#丸太iをKi回切る場合、その丸太の最小はL//Kiとなる
#あとは、どの丸太を何回切るかを求めればよい。
"""
長い丸太ほど多く切るべき
丸太が2本、1本が10**9でもう一本が1。10**9回切れるのであれば1本目に全振りするのがベスト。
結論、元の長さの比に基づいて割り当てればよい。
一番短い丸太の長さを1として各丸太の
"""
from math import ceil
import heapq
N,K = list(map(int,input().split()))
A = list(map(int,input().split()))
A.sort()
pivot = A[0]
hiritu = [int(ceil(a/pivot)) for a in A]
hirituSum = sum(hiritu)
kaisu = []
for i in range(N):
h = hiritu[i]
k = int(K*h/hirituSum)
kaisu.append(k)
K -= k
"""
if K >= 1000000:
for i in range(N):
h = hiritu[i]
k = int(ceil(K*h/hirituSum))
kaisu.append(k)
K -= k
"""
leng = []
for i in range(N):
a = A[i]
k = kaisu[i]
leng.append(((-a/(k+1)),k,a))
heapq.heapify(leng)
for _ in range(K):
l,k,a = heapq.heappop(leng)
l = -a/(k+2)
heapq.heappush(leng,(l,k+1,a))
l,k,a = heapq.heappop(leng)
l *= -1
print((ceil(l)))
|
from math import ceil
N,K = list(map(int,input().split()))
A = list(map(int,input().split()))
def is_ok(X):
#最大値をX以下にできるか
cnt = 0
for a in A:
cnt += ceil(a/X)-1
return cnt <= K
def bisearch(high,low):
while high - low > 1:
mid = (high+low)//2
if is_ok(mid):
high = mid
else:
low = mid
return high
print((bisearch(10**9+1,0)))
|
p02598
|
import math
n, k = list(map(int, input().split()))
aas = list(map(int, input().split()))
left = 1
right = 10**9
def judge(mid):
cut = 0
for i in aas:
cut += math.ceil(i / mid) - 1
if cut <= k:
return True
else:
return False
while left < right:
mid = (left + right) / 2
if math.ceil(left) == math.ceil(right):
break
elif judge(mid):
right = mid
else:
left = mid
print((math.ceil(left)))
|
import math
n, k = list(map(int, input().split()))
aas = list(map(int, input().split()))
diff = pow(10,-6)
left = 1
right = 10**9
def judge(mid):
cut = 0
for i in aas:
cut += math.ceil(i / mid) - 1
if cut <= k:
return True
else:
return False
while left < right:
mid = (left + right) / 2
if (left <= right <= left + diff) or (right <= left <= right + diff):
break
elif judge(mid):
right = mid
else:
left = mid
print((math.ceil(left)))
|
p02598
|
n, k = list(map(int, input().split()))
a = sorted(list(map(int, input().split())))[::-1]
l = 0
r = a[0] + 1
ref = 0
ans = a[0]
while r - l > 1:
now = (l + r)//2
for i in a:
ref += 0 - -i//now - 1
if ref > k:
ref = 0
l = now
break
else:
ans = min(ans, now)
ref = 0
r = now
print(ans)
|
n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
l = 0
r = 10**9 + 1
ref = 0
ans = 10**9
while r - l > 1:
now = (l + r)//2
for i in a:
ref += 0 - -i//now - 1
if ref > k:
ref = 0
l = now
break
else:
ans = now
ref = 0
r = now
print(ans)
|
p02598
|
n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
l = 0
r = 10**9 + 1
ref = 0
ans = 10**9
while r - l > 1:
now = (l + r)//2
for i in a:
ref += 0 - -i//now - 1
if ref > k:
ref = 0
l = now
break
else:
ans = now
ref = 0
r = now
print(ans)
|
n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
l = 0
r = 10**9 + 1
ref = 0
ans = 10**9
while r - l > 1:
now = (l + r)//2
for i in a:
ref += 0 - -i//now - 1
if ref <= k:
ans = now
ref = 0
r = now
else:
ref = 0
l = now
print(ans)
|
p02598
|
while True:
try:
xA,yA,xB,yB,xC,yC,xD,yD = list(map(float, input().split()))
if abs((yB-yA)*(yD-yC) + (xB-xA)*(xD-xC)) < 1.e-12:
print("YES")
else:
print("NO")
except:
break
|
while True:
try:
xA,yA,xB,yB,xC,yC,xD,yD = list(map(float, input().split()))
if abs((yB-yA)*(yD-yC) + (xB-xA)*(xD-xC)) < 1.e-10:
print("YES")
else:
print("NO")
except:
break
|
p00058
|
from functools import reduce
def M(x, y):
if x == 'T' and y == 'T':
return 'T'
elif x == 'T' and y == 'F':
return 'F'
elif x == 'F' and y == 'T':
return 'T'
else:
return 'T'
_ = eval(input())
P = input().split()
print((reduce(M, P)))
|
from functools import reduce
def M(x, y):
if x == 'T' and y == 'F':
return 'F'
else:
return 'T'
_ = eval(input())
P = input().split()
print((reduce(M, P)))
|
p02038
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.