Variable Sized Arrays

  • + 0 comments

    int main() {

    int n, q, size, value, which, index;
    
    cin >> n >> q;
    vector<vector<int>> vec1; //initializing a 2d vector
    for (int i = 0; i < n; ++i) {
        cin >> size;
        vector<int> vec2;
        for (int j = 0; j < size; ++j) {
            cin >> value;
            vec2.push_back(value);
        }
        vec1.push_back(vec2);
    }
    for (int k = 0; k < q; ++k) {
        cin >> which >> index;
        cout << vec1[which][index] << endl;
    }  
    return 0;
    

    }