Untitled

                Never    
C++
       
#include <iostream>
#include <vector>
#include <queue>
#include <map>

using namespace std;

map<int, queue<int>> m;
map<int, int> kid;
vector<int> ans;
vector<int> candy;

int main(void){
    int N, M, sz, tmpc, tmpcandy;
    cin >> N >> M;
    for(int i = 1; i <= N; i++){
        cin >> kid[i];
        for(int j = 0; j < kid[i]; j++){
            cin >> tmpc;
            m[tmpc].push(i);
        }
    }
    for(int i = 0; i < M; i++){
        cin >> tmpcandy;
        candy.push_back(tmpcandy);
        if(!m[tmpcandy].empty()){
            ans.push_back(m[tmpcandy].front());
            kid[m[tmpcandy].front()]--;
            m[tmpcandy].pop();
        }
        else
            ans.push_back(0);
    }
    //cout << "ans\n";
    for(int i = 0; i < M; i++){
        if(kid[ans[i]] > 0)
            ans[i] = 0;
        cout << ans[i] << endl;
    }
}

Raw Text