QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#593253#8243. Contest Advancementenze#WA 0ms3576kbC++201.7kb2024-09-27 12:56:382024-09-27 12:56:38

Judging History

你现在查看的是最新测评结果

  • [2024-09-27 12:56:38]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3576kb
  • [2024-09-27 12:56:38]
  • 提交

answer

#include <iostream>
#include <vector>
#include <unordered_map>
#include <algorithm> // Include this header for std::find

using namespace std;

int main() {
    int n, k, c;
    cin >> n >> k >> c;

    vector<pair<int, int>> teams(n); // Pair of team ID and school ID
    for (int i = 0; i < n; i++) {
        cin >> teams[i].first >> teams[i].second;
    }

    vector<int> selected_teams;          // IDs of selected teams
    unordered_map<int, int> school_count;  // Count of teams selected per school

    int selected_count = 0;
    vector<bool> selected(n, false); // Keep track of whether team at index i is selected

    // First Pass: Select teams within the school limit
    for (int i = 0; i < n && selected_count < k; i++) {
        int school_id = teams[i].second;

        if (school_count[school_id] < c) {
            selected_teams.push_back(teams[i].first); // Store team ID
            school_count[school_id]++;
            selected_count++;
            selected[i] = true;
        }
    }

    // Second Pass: Fill remaining slots with teams over the school limit
    if (selected_count < k) {
        for (int i = 0; i < n && selected_count < k; i++) {
            if (!selected[i]) {
                // Select this team regardless of the school limit
                selected_teams.push_back(teams[i].first); // Store team ID
                // No need to increment school_count here
                selected_count++;
                // selected[i] = true; // Optional, since we're done after this
            }
        }
    }

    // Output the selected teams in rank order
    for (int id : selected_teams) {
        cout << id << endl;
    }

    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3576kb

input:

10 7 3
3 9
1 9
4 9
5 9
9 7
2 7
6 7
7 7
8 5
10 5

output:

3
1
4
9
2
6
8

result:

ok 7 lines

Test #2:

score: -100
Wrong Answer
time: 0ms
memory: 3576kb

input:

10 5 2
1 1
2 1
3 1
4 1
5 1
6 1
7 1
8 1
9 1
10 2

output:

1
2
10
3
4

result:

wrong answer 3rd lines differ - expected: '3', found: '10'