Wrong answer in chef and fruits

#include <stdio.h>
#include<math.h>
int main()
{
int m,n,k,t,diff;
scanf(“%d”,&t);
for(int i=0;i<t;i++)
{
scanf(“%d%d%d”,&m,&n,&k);
diff=abs(m-n);
if(diff>=k)
diff=diff-k;
else
{
k=k-diff;
diff=k%2;
}
printf(“%d\n”,diff);
}}

What answer does your program give for

1
4 2 3

? What should it be?

1 Like

Read the question properly please.

It is saying that Chef can purchase fruits ‘at most’ k times and NOT ‘exactly’ k times. You are finding the answer for ‘exactly’ k times.

Hope this helps :slight_smile:

1 Like