please please.. why it has runtime error? please help

#include<stdio.h>

struct exor{
	int first;
	int second;
};
int main(){
	int t; struct exor a[100];
	int i,j,m,n,mini,count=0;	
	
	scanf("%d",&t);
	while(t--){
		scanf("%d %d",&n,&m);
	for(i=1;i<=m;i++){
		scanf("%d %d",&a[i].first,&a[i].second);	
		}
	
//	min=n;
mini=2000;
	for(i=1;i<=m;i++){
		if(a[i].second==n&&a[i].first<=mini){
		mini=a[i].first;
	//	mini=i;
	}
	}
	
/*	if(i==n)
	printf("2%d",n);*/
	
	for(j=1;j<=n;j++){
		
			if(a[i].first==mini)
			count++;
	}
	if(mini==2000){
		printf("2 %d\n",n);
	}
	else if(count==(n-mini)){
	printf("2 %d\n",mini);
	}
	else if(count!=(n-mini)){
		printf("1\n");
	}
	else{
		printf("0\n");
	}
}
return 0; 
}

problem: http://www.codechef.com/ACMAMR12/problems/ATKCTR

@avanee : You should give us the link to the problem and your submission . You have pasted your code which is OK , but we don’t know what kind of input it will be subjected to while running because we don’t have link to the problem . Therefore we don’t know when it might throw an exception / crash .

What problem you are trying to solve? ATKCTR?

sure sir itz… http://www.codechef.com/ACMAMR12/problems/ATKCTR

If you are solving ATKCTR, why is your a array length 100?

@betlisha … ya tz tht… :slight_smile: please help sir

The simplest reason, that appears at a single look on your code is because, you have some loops running from 1 to m, which has some array indexing in them. Make sure that no “out of index” accesses occur in the array. What is the max value m can have? (Keep in mind, array indexing starts from 0. So, if max possible value for m is >= 100, then a[i] when i=100 is prone to crash.)

i also hv made changes up to size 30 bt still same problem…:frowning:

@betlista has already pointed out . Note the constraint below given in the problem .
0 <= M <= min(N(N-1)/2, 300,000)
You have written the code :
for(i=1;i<=m;i++){
if(a[i].second==n&&a[i].first<=mini){
So your array a , should have indices upto ‘m’ defined , right ?? So your array should be 3,00,000 in size .

@avanee , you are running loop from 1 to m , either make it 0 to m-1 or make your array of size 3,00,001

30 is even smaller, according to statement MAXM is 300.000 = 3*10^5.

sir please make it correct so tht it dsnt hv run time error … please …

@ i ws thinking tht 300000 will b very high tht y … m trying again sir…