DOWNLOAD: rte

#include
using namespace std;
main()
{
int N,Q,l=0, temp;
cin>>N;
int T[N][2];
for(int i=0; i<N; i++)
cin>>T[i][0]>>T[i][1];
cin>>Q;
int q[Q],t[100];
bool a[N];
for(int j=0; j<Q; j++)
{
cin>>q[j];
temp=q[j];
while(temp)
{
cin>>t[l];
l++;
temp–;
}
}
temp=Q;
int g=0;
while(temp)
{
int count=0;
for(int n=0; n<N; n++)
a[n]=0;
for(int m=0; m<q[Q-temp]; m++)
{
for(int o=0; o<N; o++)
{
if(T[o][0]<=t[g] && T[o][1]>=t[g] && a[o]==0)
{
a[o]=1;
count++;
}

            }  
            g++;          
        }  
        cout<<count<<'\n';  
        temp--;  
    }      
}  

//what’s wrong with the following code. why i’m getting run-time error

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…

I’m not able to get it.
If it is not allowed to use cin/cout here, even i had tried using printf/scanf but same runtime error occurs.

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?

@sarveshgpt1991: generate the input file using the code above and your code will get runtime error…

You can use this question for further discussion.