Skip to content

Instantly share code, notes, and snippets.

@maehrm
Created February 8, 2026 00:57
Show Gist options
  • Select an option

  • Save maehrm/b87bb8a06546340ae1505aaa35b56477 to your computer and use it in GitHub Desktop.

Select an option

Save maehrm/b87bb8a06546340ae1505aaa35b56477 to your computer and use it in GitHub Desktop.
import math
def can(length): # 各丸太をlength以下にできるか?
cuts = 0
for i in range(N):
cuts += math.ceil(A[i] / length) - 1
return cuts <= K
N, K = map(int, input().split())
A = list(map(int, input().split()))
ng, ok = 0, max(A)
while ok - ng > 1:
mid = (ok + ng) // 2
if can(mid):
ok = mid
else:
ng = mid
print(ok)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment