Why wrong answer

#include<stdio.h>

int main()
{
int i,n,a[10000],b[10000],c[10000],e[10000],max1=0,max2=0,m=0,k=0;

scanf("%d\n",&n);

for(i=0;i<n;i++)
{
	scanf("%d %d",&a[i],&b[i]);
	if(a[i]>b[i])
	{
		c[m]=a[i]-b[i];
		m++;
		
	}
	if(b[i]>a[i])
	{
		e[k]=b[i]-a[i];
		k++;
	}
}
max1=c[0];
max2=e[0];
for(i=0;i<n-1;i++)
{	
	if(c[i+1]>c[i])
	{
		max1=c[i+1];
	}
	if(e[i+1]>e[i])
	{
		max2=e[i+1];
	}
}
if(max1>max2)
{
	printf("%d %d",1,max1);
}
else if(max2>max1)
{
	printf("%d %d",2,max2);
}
return 0;

}

@itsayushbansal You are incrementing the value of m and k so its not for sure that both get the same values. Plus your loop from 0 to n-1 is wrong because arrays c and e do not even contain as many elements, they have elements equal to m and k respectively. Change that. Plus use “\n” while printing the result.

Link to problem, please?

1 Like

http://www.codechef.com/viewsolution/5130174

Thanks a lot :slight_smile:

http://www.codechef.com/viewsolution/5132254

still getting wrong answer.Why??

Scanning a[i] and b[i] has problem, check it out.

Cannt understand…plzz help.

There’s no space in between them.

Again Wrong.:frowning:

http://www.codechef.com/viewsolution/5132383

plzz help.