Try to find out what is max value for m in this loop:
for(int m=0; m<q[Q-temp]; m++)
you are using t[g] in this loop…
edit:
use this code to generate the input file:
#include <cstdio>
#define N 100000
#define Q 5000
int main() {
printf( "%d\n", N );
for ( int i = 0; i < N; ++i ) printf( "%d %d\n", 1, i + 1 );
printf( "%d\n", Q );
for ( int i = 0; i < Q; ++i ) printf( "%d %d\n", 1, 100000000 );
return 0;
}
BTW: according to FAQ, you main method has to have int return value…
You can use cin/cout or printf/scanf but you declared t as aray with at most 100 elements and my hint was to figure out what is the max value for m. Why? Because in for loop I wrote about in my answer you are increasing g and later you are using t[g], but what if max value for m is bigger than 100?