Datasets:
Download code/math_code_016_solution.py from efe-T/bilingual-math-code-verification-v1: direct link, hf CLI and curl.
- Browser
- Download file 635 Bytes
-
https://huggingface.co/datasets/efe-T/bilingual-math-code-verification-v1/resolve/main/code/math_code_016_solution.py
- Command line
-
hf download hf://datasets/efe-T/bilingual-math-code-verification-v1/code/math_code_016_solution.py
-
curl -L -o math_code_016_solution.py https://huggingface.co/datasets/efe-T/bilingual-math-code-verification-v1/resolve/main/code/math_code_016_solution.py
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)) | |