PLAYFIT - Wrong Answer

In the problem fit to play(http://www.codechef.com/problems/PLAYFIT). I am getting wrong answer on the code I used even though I tried all the cases I could think of and I get right answers.Please help.Here’s my code.

#include<iostream>
#define big 100000

int main()
{
int cases;
long matches[big]={0},num,i,j,ans[11]={0},l,max=0;
scanf("%d",&cases);
for(int k=0;k<cases;k++)
{
	scanf("%ld",&num);
	for(i=0;i<num;i++)
	{
		scanf("%ld",&matches[i]);
	}
	for(l=0;l<(num-1);l++)
	{
		if(matches[l+1]-matches[l]>max)
		{
			max=matches[l+1]-matches[l];
		}
	}
	if(max>0)
	{
		printf("%ld\n",max);
	}
	else
	{
		printf("UNFIT\n");
	}
	for(j=0;j<num;j++)
	{
		matches[j]=0;
	}
	max=0;
}
}

You are just considering the consecutive matches in your code to maximize the difference but as the problem states that we can consider any two matches.

For example consider the following array of goals.
5 6 8 9 10

I think that your code will output 2 i.e. 8-6
but actually answer is 5 i.e 10-5.

I hope this helped.

1 Like

I am sure thats not the case look at the sample test cases provided actually the first one you will get to know.

but it is possible in other test cases.