Help me in solving BOUQUET problem

My issue

My code

#include <iostream>
#include<cmath>
using namespace std;
#define ll long long
#define yes cout<<"YES\n"
#define no cout<<"NO\n"
void solve(){
    ll m[3],o[3],p[3],suma,sumb,sumc;
    std::cin >> m[0]>>m[1]>>m[2]>>o[0]>>o[1]>>o[2]>>p[0]>>p[1]>>p[2];
    suma=m[0]+m[1]+m[2];
    sumb=o[0]+o[1]+o[2];
    sumc=p[0]+p[1]+p[2];
    ll ans1=max(suma,sumb);
    ll ans2=max(suma,sumc);
    ll ans=0, temp=0;
    for(int i=0;i<3;i++)
    {temp= p[i]+m[i]+o[i];
    ans=max(temp,ans);
}
ll finalans=max(ans,ans2);
if(ans%2==0)
ans=ans-1;
std::cout << ans << std::endl;
}
int main() {
	int t;
	std::cin >> t;
	while(t--)
	{
	    solve();
	}
	return 0;
}

Problem Link: BOUQUET Problem - CodeChef

I am getting WA everytime I submit.can anyone let me know why?

@itz_vishnu
u have missed one case if the ans is 0 then it will return -1 .
i have coded in much simpler way hope u will get it .
include
using namespace std;

int main() {
// your code goes here
int t;
cin>>t;
while(t–)
{
long long int a[3][3];
long long int ans=0,sm=0;
for(int i=0;i<3;i++)
{
sm=0;
for(int j=0;j<3;j++)
{
cin>>a[i][j];
sm+=a[i][j];
}
ans=max(ans,sm);
}
for(int i=0;i<3;i++)
{
sm=0;
for(int j=0;j<3;j++)
{
sm+=a[j][i];
}
ans=max(ans,sm);
}
if(ans%2==0&&ans!=0)
ans–;
cout<<ans<<endl;
}
return 0;
}

1 Like