Can anyone explain me the condition 3 4 4 ? According to the formula the answer is coming as 0.
But the answer should come as 1.
Can anyone explain me this?
Calculate the absolute difference between no. of apples and oranges. We can further minimize this difference by buying either of apple or oranges accordingly:
int diff = abs(n-m)-k;
Spend all our coins to buy fruits accordingly. Minimum absolute difference can be 0 only, so for negative answer output 0 i.e. dont spend more coins afterwards we’ve equal no. of fruits:
/when i run this program on codeblock the output is correct it also satisfy the test case of this question but when i submit it it give the wrong answer what can i do please give some suggestion/
#include<bits/stdc++.h>
using namespace std;
int main(void)
{
int i,j,b,n,q;
cin>>q;
while(q–)
{
cin>>n;
int a[100];i=0;
a[i]=n;
for(i=1;i<n+1;i++)
cin>>a[i];b=1;
for(i=1;i<n;i++)
{
for(j=b>a[i]?b:a[i];a[i]%j || a[i+1]%j;j–);b=j;
}
for(i=1;i<n+1;i++)
{
a[i]=a[i]/b;
}
for(i=1;i<n+1;i++)
{
cout<<a[i]<<" ";
}
The testcase 5 4 4 is not giving the right answer.
It is giving answer 0 but actually it should be 1. can anyone tell why> and if it is true edtior approach is wrong.
Please try to indent your code properly before submitting here if you want anyone to help you. I promise I will help you with this once you get this code all clearly indented. You can do so by just provide 4 times spaces before each line of your code.
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;
}