My issue
include
using namespace std;
int main() {
// your code goes here
long long int t,n;
cin>>t;
int a,b,c;
for(int i=0;t>0;t–){
cin>>n;
a=(int)n/3;
b=a;
c=n-a-b;
if(a%2==0 && b%2==0 && c%2==0){
a=a-1;
b=a;
c+=2;
}
cout<<a<<" “<<b<<” "<<c<<endl;
}
return 0;
}
This is my code for chocolate distribution problem I know the solution can be 1 1 and n-2 but what I dont understand is why is my approach not working. I took 3 people a,b,c and then a got (int)n/3 chocolates, b got the same chocolates as a and c got the remaming ones. If all 3 values are even then 1 is dedcuted from both a and b and 2 is added to c. Please someone explain to me why is this not working I am getting all the ouput correct but failing one test cases
My code
#include <iostream>
using namespace std;
int main() {
// your code goes here
long long int t,n;
cin>>t;
int a,b,c;
for(int i=0;t>0;t--){
cin>>n;
a=(int)n/3;
b=a;
c=n-a-b;
if(a%2==0 && b%2==0 && c%2==0){
a=a-1;
b=a;
c+=2;
}
cout<<a<<" "<<b<<" "<<c<<endl;
}
return 0;
}
Problem Link: CHOCOCHEF Problem - CodeChef