Chef & stones greedy algorithms

#include<bits/stdc++.h>

using namespace std;
int main()
{
int t;
cin>>t;
while(t–)
{
int n1,n2,m,sum=0;
cin>>n1>>n2>>m;

for(int i=1;i<=m;i++)
{
    n1=n1-i;

    n2=n2-i;
    if(i==m)
    {
        sum=n1+n2;
    }
}
cout<<sum<<"\n";


}

}

what’s problem with the code

Please either format your code or (better!) link to your submission - the forum software has mangled it and it won’t compile! :slight_smile:

I’m going by your most recent submission. The if doesn’t include both the statements. Also the problem is solvable in constant time. Your loop is also in the wrong direction. It should go from m to 1.