Wednesday, 21 September 2016

Variable Sized Arrays

#include <iostream>
using namespace std;

int main() {
int n,q;
cin>>n>>q;
int** seq=new int* [n];
for(int i=0;i<n;i++)
    {
      int a;
      cin>>a;
      int* b=new int [a];
      for(int j=0;j<a;j++)
        {
          int e;
          cin>>e;
          b[j]=e;
        }
    *(seq+i)=b;
   }

  for(int i=0;i<q;i++)
  {
  int r,s;
  cin>>r>>s;
  cout<<seq[r][s]<<endl;
  }
    return 0;
}

Sample Input
2 2
3 1 5 4
5 1 2 8 9 3
0 1
1 3
Sample Output
5
9
Explanation
For the first query, the sequence is . Hence, the answer is .
For the second query, the sequence is . Hence, the answer is .

No comments:

Post a Comment