DOWNLOAD: Need help

link text

hi… my code is correct to the point if i take Q=1 only…

for(i=0;i<q;i++)
{
scanf("%lld",&g);
for(i=0;i<g;i++)
scanf("%lld",&k[i]);
}

on doing this my code will replace the value of previous k[]…there would be many arrays req. this way.

please tell how to overcome this part.

#include<stdio.h>  
int main()  
{  
long long sum,n,a,i,count=0,s[100000],k[100000],e[100000],q,g,j;  
scanf("%lld",&n);  
for(i=0;i<n;i++)  
scanf("%lld %lld",&s[i],&e[i]);  
scanf("%lld",&q);  
/*for(i=0;i<q;i++)  
{*/  
scanf("%lld",&g);   
for(i=0;i<g;i++)  
scanf("%lld",&k[i]);  
// }  
for(i=0;i<g;i++){  
for(j=0;j<n;j++){  
if(k[i]<=e[j]&&k[i]>=s[j])  
{  
count++;  
s[j]=0;e[j]=0;  
}  
printf("%lld \n",count);    
printf("%lld %lld\n",s[j],e[j]);    
}  
}  
printf("%lld\n",count);    
return 0;  
}  

When you want to read the array from stdin, you have to allocate memory () for such array and then read the values one by one.

To do that there is typically information in input how long the array is or what is the max length. So typically you can do something like:

int q;
scanf( "%d", &q );
int k[q];
for ( int i = 0; i < q; ++i ) scanf( "%d", &k[i] );

If the information about array length is missing you can do

#devine MAXN 1000
...
int k[MAXN];
...

You have to realize also that MAXN is 10^5 and MAXQ is 5*10^3 in this problem, so your solution runs in worst case in O(MAXN*MAXQ) time, that’s 5*10^8 - too slow.

You can discuss about this here as well.