i also did the same Still confused why its Wrong
Whats wrong with my code i donāt understand. Its giving me a wrong answer !! Can someone help me ?
#include <iostream>
using namespace std;
int main() {
int t;
cin>>t;
while(t--)
{
int n,m,k ;
cin>>n>>m>>k;
int i=0 ; // here i is the count of coins
while(true)
{
if(n<m)
n+=1 ;
else
m+=1 ;
i++ ;
if(i==k) // if number of coins are k then terminate
break ;
}
cout<<abs(n-m)<<"\n";
}
return 0;
}
#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.