bilingual-math-code-verification-v1 / code /math_code_016_solution.py
efe-T's picture
Upload folder using huggingface_hub
93237a0 verified
Raw History Blame Contribute Delete
635 Bytes
weights = [7, 2, 5, 10, 8]
def days_needed(capacity):
days, load = 1, 0
for weight in weights:
if weight > capacity:
return len(weights) + 1
if load + weight > capacity:
days += 1
load = 0
load += weight
return days
lo, hi = max(weights), sum(weights)
while lo < hi:
mid = (lo + hi) // 2
if days_needed(mid) <= 2:
hi = mid
else:
lo = mid + 1
assert days_needed(lo) <= 2 and days_needed(lo - 1) > 2
result = {"capacity": lo, "days_at_capacity": days_needed(lo)}
import json
print(json.dumps(result, ensure_ascii=False, sort_keys=True))