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

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

Archive30 Cases

四大文化赛道完整展开

AccessHTTPS

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

No Rounded CornersTailwind FirstDossier Ready
03-execution/run-002/source-snapshot/main.cpp

main.cpp

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

文件类型.cpp

10-cases/s2-jh-08-team-roster/03-execution/run-002/source-snapshot/main.cpp

#include <iostream>
#include <vector>

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int n, limit;
    if (!(cin >> n >> limit)) {
        return 0;
    }
    vector<pair<int, int>> items(n);
    for (int i = 0; i < n; ++i) {
        cin >> items[i].first >> items[i].second;
    }
    vector<long long> scores(limit + 1, -1);
    vector<int> counts(limit + 1, 1e9);
    scores[0] = 0;
    counts[0] = 0;
    for (const auto& item : items) {
        int hours = item.first;
        int value = item.second;
        for (int used = limit; used >= hours; --used) {
            if (scores[used - hours] == -1) {
                continue;
            }
            long long cand_score = scores[used - hours] + value;
            int cand_count = counts[used - hours] + 1;
            if (cand_score > scores[used] || (cand_score == scores[used] && cand_count < counts[used])) {
                scores[used] = cand_score;
                counts[used] = cand_count;
            }
        }
    }
    long long best_score = -1;
    int best_hours = 0;
    int best_size = 0;
    for (int used = 0; used <= limit; ++used) {
        if (scores[used] == -1) {
            continue;
        }
        if (best_score == -1 || scores[used] > best_score ||
            (scores[used] == best_score && used < best_hours) ||
            (scores[used] == best_score && used == best_hours && counts[used] < best_size)) {
            best_score = scores[used];
            best_hours = used;
            best_size = counts[used];
        }
    }
    cout << "best_score=" << best_score << "\n";
    cout << "used_hours=" << best_hours << "\n";
    cout << "team_size=" << best_size << "\n";
    return 0;
}