Untitled

mail@pastecode.io avatar
unknown
c_cpp
6 days ago
1.8 kB
1
Indexable
Never
#include <iostream>
#include <set>
#include <vector>
#include <map>
using namespace std;

int main() {
    int M, N;
    cin >> M >> N;
    vector<vector<int>> littleCute(M);
    vector<int> jobOwner(N, 0);
    map<int, set<int>> jobType;

    // Read the job requests for each little cute
    for (int i = 0; i < M; i++) {
        int size;
        cin >> size;
        for (int j = 0; j < size; j++) {
            int type;
            cin >> type;
            littleCute[i].push_back(type);
        }
    }

    // Read the job types
    for (int i = 1; i <= N; i++) {
        int type;
        cin >> type;
        jobType[type].insert(i);
    }

    // Process each little cute in order
    bool cry = false;
    for (int i = 0; i < M && !cry; i++) {
        vector<int> takenJobs;  // To store the jobs taken by the current little cute
        bool failed = false;

        // Try to get all the desired jobs for the current little cute
        for (int type : littleCute[i]) {
            if (jobType[type].empty()) {
                failed = true;
                break;
            } else {
                int jobId = *jobType[type].begin();
                jobType[type].erase(jobId);
                takenJobs.push_back(jobId);
            }
        }

        // If the current little cute failed, mark `cry` and stop processing further
        if (failed) {
            cry = true;
        } else {
            // Assign the jobs to the current little cute
            for (int jobId : takenJobs) {
                jobOwner[jobId - 1] = i + 1;
            }
        }
    }

    // Output the job owners
    for (int owner : jobOwner) {
        cout << owner << endl;
    }

    return 0;
}
Leave a Comment