World Robot Contest2025-2026Algorithm Application ThemeJunior Highwrc.hao.work
WRC
Contest Archive / Structured Dossiers青少年算法应用训练档案馆

把训练题、知识点、执行证据和最终解题档案统一归档成可直接浏览的竞赛资料库。

Archive30 Cases

四大文化赛道完整展开

AccessHTTPS

完整题面 / 题解 / 运行证据

No Rounded CornersTailwind FirstDossier Ready
02-solution/src/python/main.py

main.py

站内文件视图直接读取仓库内容,Markdown 使用文档排版渲染,其余文本文件保持原始排版,方便校对训练证据链。

文件类型.py

10-cases/s2-jh-08-team-roster/02-solution/src/python/main.py

import sys


def solve(data: str) -> str:
    tokens = list(map(int, data.split()))
    if not tokens:
        return ""
    it = iter(tokens)
    n = next(it)
    limit = next(it)
    items = [(next(it), next(it)) for _ in range(n)]
    scores = [-1] * (limit + 1)
    counts = [10 ** 9] * (limit + 1)
    scores[0] = 0
    counts[0] = 0
    for hours, value in items:
        for used in range(limit, hours - 1, -1):
            prev_score = scores[used - hours]
            if prev_score == -1:
                continue
            cand_score = prev_score + value
            cand_count = counts[used - hours] + 1
            if cand_score > scores[used] or (cand_score == scores[used] and cand_count < counts[used]):
                scores[used] = cand_score
                counts[used] = cand_count
    best_score = -1
    best_hours = 0
    best_size = 0
    for used in range(limit + 1):
        if scores[used] == -1:
            continue
        candidate = (scores[used], -used, -counts[used])
        current = (best_score, -best_hours, -best_size)
        if best_score == -1 or candidate > current:
            best_score = scores[used]
            best_hours = used
            best_size = counts[used]
    return "\n".join(
        [
            f"best_score={best_score}",
            f"used_hours={best_hours}",
            f"team_size={best_size}",
        ]
    )


if __name__ == "__main__":
    sys.stdout.write(solve(sys.stdin.read()).strip())
    sys.stdout.write("\n")