#include<bits/stdc++.h>

using namespace std;

int main()

{

int t,m,n,k;

cin>>t;

while(t–)

{

cin>>n>>m>>k;

while(k)

{

if(m<n)

{m++;k–;

}

else if(n<m)

{n++;k–;

}

else{m++;k–;}

}

cout<<abs(n-m)<<"\n";

}

}

#include<bits/stdc++.h>

using namespace std;

int main()

{

int t,m,n,k;

cin>>t;

while(t–)

{

cin>>n>>m>>k;

while(k)

{

if(m<n)

{m++;k–;

}

else if(n<m)

{n++;k–;

}

else{m++;k–;}

}

cout<<abs(n-m)<<"\n";

}

}

Ig t- will be t-- and same for k-

yes i know and in my program it is - - but while submitting here this happened… sorry and thanks alot for your concern. please can you do it urslef when you are runing and then tell me maybe…

Do post a link to the question you have a query about.

Also posting a link to your submitted code is always better than pasting your code here and expecting someone to help

1 Like

Have a look at this.

- You are missing out the case where you already have m = n and you have to do nothing with your k coins.
- Also, by applying while loop in your code, you are exhausting all your coins. But that is not necessary. You always want to save the money you have right?

2 Likes

okay… thanks btw my question remains… that for the input provided by the site my program gives the same ans as that of the output provided. WHY IS THAT. btw thank you very much for your concern this will help me in my future programs…

The input provided by the site are known as ‘Sample Test Cases’. Your program will run against each test case of the problem the system contains. If it passes all of them, you will get an AC, if it fails on any one, you will get a WA or any other verdict.

Hope this helps

1 Like

Consider the input 5 5 3, m and n are already equal so you need not spend any coins and the output should be 0.

But your code produces 1 as output. This is just one such example where your code fails. There’ll be many others…

1 Like