Variable Sized Arrays

  • + 0 comments
    #include<bits/stdc++.h>
    using namespace std;
    
    int main() {
        ios_base::sync_with_stdio(0), cin.tie(0); //optimization lines
        int n, q;
        cin>>n>>q;
        
        vector<vector<int>>arr(n); //create an array of arrays
        
        for(int i = 0; i < n; i ++){ //fill the array of arrays
            int k; 
            cin>>k;
            arr[i].resize(k); // we give the array in position i the size of k 
            for(int j = 0; j < k; j++){
                cin>>arr[i][j];
            }
        }
        
        for(int i = 0; i < q; i++){
            int x,y;
            cin >> x >> y;
            cout << arr[x][y] << endl;
        }
        return 0;
    }