Can anyone please suggest me the mistake in my program. As, the testcases I am able to think gives the correct output, but instead it is showing wrong answer.
I will be very much thankful to the one who helps me…
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main() {
// your code goes here
//freopen(“input.txt”,“r”,stdin);
int t;
cin>>t;
while(t–){
int a,b,c;
cin>>a>>b>>c;
long long sum1 = 0;
long long sum2 = 0;
if(c%2 == 1){
sum1 += 3;
c--;
}
int x = c / 2;
sum1 += 3*x;
sum2 += 3*x;
if(b%2 != 0){
if(sum1<sum2){
sum1 += 2;
}else
sum2 += 2;
b--;
}
x = b / 2;
sum1 += 2*x;
sum2 += 2*x;
long long diff = sum1 - sum2;
if(a >= diff){
a = a - diff;
if(a%2 == 0){
cout<<"Yes"<<endl;
}else
cout<<"No"<<endl;
}else{
cout<<"No"<<endl;
}
}
return 0;
Can someone please tell what is wrong in my code?? Thanks
#include<bits/stdc++.h>
using namespace std;
int main()
{
int tc;
cin>>tc;
int a,b,c,q1,q2,q3;
while(tc--)
{
cin>>a>>b>>c;
long int sum = a + b*2 + c*3;
if(sum%2==1)
cout<<"NO\n";
else
{
sum=sum/2;
q3=sum/3;
sum = sum - min(q3,c)*3;
q2=sum/2;
sum = sum - min(q2,b)*2;
q1=sum/1;
sum = sum - min(q1,a);
if(sum>0)
cout<<"NO\n";
else
cout<<"YES\n";
}
}
}
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
ios_base::sync_with_stdio(false); cin.tie(NULL);
ll t; cin >> t;
while (t--) {
ll a, b, c;
cin >> a >> b >> c;
if ((a + c) % 2 == 0) {
if (a > 0 and b > 0 and c > 0)
cout << "YES" << "\n";
else if (a + b == 0 or a + c == 0 or b + c == 0) {
if ((a + b + c) % 2 == 0)
cout << "YES"<< "\n";
else
cout << "NO" << "\n";
} else if (a == 0 and b > 1)
cout << "YES" << "\n";
else if (b == 0 and a > 1)
cout << "YES"<< "\n";
else if (c == 0)
cout << "YES"<< "\n";
else
cout << "NO" << "\n";
} else
cout << "NO" << "\n";
}
return 0;
}
s = 1A + 2B + 3C
=> (2-1)A + 2B + (2 + 1)C
=> 2(A +B + C) + (C-A)
NOW
S/2 = (A +B +C) + (C-A)/2
entire problem depends upon weather c-a is even or not
just run a loop that sees if c-a is even then calculate S based upon above equation, i suppose it might work