Help Plzz.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;

}

Can you please post link to the problem?

1 Like

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

@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.

if max1 and max2 are same then there will not be any value to print…
and also same mistake in scaning for loop if a[i] and b[i] are same…

it is given in ques to avoid tie cases

1 Like