Today is Caleb's birthday. His dad has surprised him with truly fruity gifts: 2 fruit baskets. The first basket contains N Avacados, and the second one contains M dragon fruits. Caleb likes Avacados and Dragon fruits very much but he likes them equally, and therefore, wants to have the minimum possible difference between the number of Avacados and Dragon fruits he has. To do so, he can purchase 1 Avacado or 1 Dragon fruit by paying exactly 1 gold coin (that's some expensive fruit, eh?). Caleb can purchase fruits at most K times (as he has only K gold coins in his pocket) to make the difference the minimum possible.
#include <stdio.h>
int main()
{int t,n,m,k;
scanf("%d",&t);
while(t>0)
{scanf("%d %d %d",&n,&m,&k);
while(k>0)
{if(n>m)
{m++;}
else if(m>n)
{n++;}
k--;}
printf("%d\n",(n-m));
t--;}
return 0;
}
Comments
Post a Comment