I'm doing a coding challenge where the aim is to take x arrays and query it y times. Each array is given a size (N) and a list of values and each query wants a specific value (b) from a specific array (a).
The input is given as follows:
X Y
N n n n ...
N n n n ...
a b
a b
Here is all of my code:
#include <vector>
#include <iostream>
using namespace std;
int main() {
int numArrays;
int numQueries;
scanf("%d %d", &numArrays, &numQueries);
vector<int*> arrays;
for (int i = 0; i < numArrays; i++)
{
int size;
scanf("%d", &size);
int arr[size];
for (int j = 0; j < size; j++)
{
scanf("%d", &arr[j]);
}
arrays.push_back(arr);
}
for (int i = 0; i < numQueries; i++)
{
int arr, ind;
scanf("%d %d", &arr, &ind);
printf("%d\n", arrays.at(arr)[ind]);
}
return 0;
}
The test input is 2 arrays and 2 queries given as follows:
2 2
3 1 2 3
5 9 8 7 6 5
0 1
1 3
The expected output should give 2 for the first query (which seems to be working fine) and then 6 for the second query however my actual output is this:
2
32767
Does anybody know why the second output comes out as 32767. This seems to be a consistent value no matter what the arrays contain or what the second query is looking for. I think it's likely something to do with my vector declaration but I'm still relatively new to C++ so I'm not sure.