#include <bits/stdc++.h>
using namespace std;
int main() {
int T;
cin>>T;
int n,m,k,d;
for(int i=0;i<T;i++){
cin>>n>>m>>k;
d = abs(n-m) - k;
if(d<0){
cout<<(-d)%2<<endl;
}else{
cout<<d<<endl;
}
}
return 0;
}
why is this wrong??
#include <bits/stdc++.h>
using namespace std;
int main() {
int T;
cin>>T;
int n,m,k,d;
for(int i=0;i<T;i++){
cin>>n>>m>>k;
d = abs(n-m) - k;
if(d<0){
cout<<(-d)%2<<endl;
}else{
cout<<d<<endl;
}
}
return 0;
}
why is this wrong??
#include<bits/stdc++.h>
using namespace std;
int main()
{
int t;
cin>>t;
while(t–)
{
int a,i,o,c;
cin>>a>>o>>c;
if(a==o)
{
if(c%2==0)
cout<<"0"<<endl;
else
cout<<"1"<<endl;
}
else
{
i=abs(a-o);
if(i>=c)
cout<<i-c<<endl;
else
if(c%2==0)
cout<<"1"<<endl;
else
cout<<"0"<<endl;
}
}
return 0;
}
Why is it wrong ?
DIid you got the reason ?
#include
using namespace std;
int main() {
int x,n=0,m=0,k=0;
cin>>x;
for(int i=0;i<x;i++){
cin>>n>>m>>k;
for(int j=0;j<k;j++){
if(n>m){
m=m+1;
}
else{
n=n+1;
}
}
if(n>m){
cout<<n-m<<endl;}
else{cout<<m-n<<endl;}
}
return 0;
}
Why wrong? please help
#include <iostream>
#include <algorithm>
#include <bits/stdc++.h>
#include <string>
#include <cmath>
using namespace std;
int main()
{
long long int n;
cin >> n;
while(n-->0){
long long int a,b,c,d,e,f,g,h,i,j,k,l;
cin >> a >> b >> c;
d = max(a,b);
e = abs(a-b);
c = c - e;
if(c<=0){
cout << abs(c) << endl;
}
else{
if(abs(c)%2==0){
cout << '0' << endl;
}
else{
cout << '1' << endl;
}
}
}
return 0;
}
/// Why is it giving wrong answer?
#include<stdio.h>
int main ( void )
{
int t = 0;
scanf("%d", &t);
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.
int main(){
int t;
cin>>t;
while(t-- >0)
{
int diff,c,n,m,k;
cin>>n>>m>>k;
c=n-m;
diff=abs©;
while(k-- >0)
{
diff=diff-1;
diff=abs(diff);
}
cout<<abs(diff)<<endl;
}
}
Why my code is giving wrong answers?
/* package codechef; // don’t place package name! */
import java.util.;
import java.lang.;
import java.io.*;
/* 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>
int main()
{
int t;
std::cin >> t;
while(t--)
{
int n,m,k;
std::cin >> n >> m >> k;
while(m!=n && k!=0)
{
if(n>m)
{
m = m+1;
k = k-1;
}
else
{
n = n+1;
k = k-1;
}
}
std::cout << abs(n-m);
std::cout << '\n';
}
return 0;
}
#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;
}```
same thing i am facing bro
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
I think there is some problem with Online judge
Online judge is wrong inthis question
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
first u spend 1coin,
it’ll bcome 3,3
again spend 1 coin
2,3
again 1
2,2
again 1
1,2
final will be 1 not 0
https://www.codechef.com/viewsolution/44099459
What is wrong with my solution? Can anybody please help me cuz its supposed to be working fine for all test cases.
@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…