FRUITS - Editorial

@ritulsingh Your Loop Stops As Soon As small == large there are many scenarios where small will be equal to large but u’ll have still coins left with you.
For Ex You Have 3 Orange 4 Apple 3 Coins
First It Ran It Became 4 Orange And 4 Apple And 2 Coins,As Apple == Orange.You Broke The Loop Now,But Still 2 Coins Are Left…

Updated answer CodeChef: Practical coding for everyone

#include<bits/stdc++.h>

using namespace std;

// 2 baskets n apples m oranges

int main(){

int t;

int n,m,k;

cin>>t;

while(t--){

    cin>>n>>m>>k;

  while(k>0){

      if(n>m){

          m++;

          k--;

      }

      else {

          n++;

          k--;

      }

  }

  cout<<n-m<<endl;

}

return 0;

}
WHY I AM GETTING THIS WRONG ??

Solution Link
CodeChef: Practical coding for everyone

t=int(input(""))
for i in range(t):
a,b,k=list(map(int,input().split()))
if(a>b):
print(a-min(b+k,a))
else:
print(b-(min(a+k,b)))