int N;
int M;
int K;
int answer[t];
for ( int i = 1 ; i <= t ; ++i)
{
scanf("%d%d%d", &N , &M , &K );
if ( N == M )
{
printf("%d\n", 0 );
}
else if ( N-M > K )
{
printf("%d\n", N-M-K );
}
else if ( N-M <= K )
{
printf("%d\n", 0 );
}
else if ( M-N > K )
{
printf("%d\n", M-N-K );
}
else if ( M-N <= K)
{
printf("%d\n", 0 );;
}
}
}
What is wrong with this code?? It is giving wrong answer.
/* Name of the class has to be “Main” only if the class is public. */
class Codechef
{
public static void main (String[] args) throws java.lang.Exception
{
// your code goes here
try {
Scanner sc=new Scanner(System.in);
int t=sc.nextInt();
while(t–>0) {
int n=sc.nextInt();
int m=sc.nextInt();
int k=sc.nextInt();
int diff=Math.abs(n-m);
int d;
if(diff<=k)
d=0;
else
d=diff-k;
System.out.println(d);
}
} catch(Exception e) {
}
}
}
#include <iostream>
#include <vector>
#include <unordered_map>
#include <set>
#include <map>
#include <algorithm>
#include <numeric>
using namespace std;
void solve() {
int m, n, k;
cin >> m >> n >> k;
int chota = min(m,n);
int bada = max(m,n);
for(int i=0; i<k; i++) {
if(bada==chota) break; // for every coin, we add it to minimum element and
// check if both are equal...
chota++;
}
cout << bada-chota << "\n";
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
int testcase;
cin >> testcase;
while(testcase--) {
solve();
}
return 0;
}```
for _ in range(int(input())):
a,b,c=list(map(int,input().split()))
for i in range(c):
if(a==b):
break
elif(a>b):
b=b+1
if(a==b):
break
else:
a=a+1
if(a==b):
break
print(abs(a-b))
CHECK THIS U WILL GET IT I HOPE… IF BOTH R EQUAL U NEED NOT BUY MORE
one common thing others are missing is that we dont have to spend all of our gold coins
we minimise the difference and if difference is 0 and we still have coins left then we dont spend it
please if you can add this in 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…