Test case 5 is not passing?

#include
using namespace std;

long long int optimal(int a[],int n,int start,int end,long long int sum)
{
if(n==1)
{
return sum;
}

if(n%2==0)//piyush turn
{
	return max(optimal(a,n-1,start+1,end,sum+a[start]),optimal(a,n-1,start,end-1,sum+a[end]));
}
else//his friend turn
{
	if(a[start]>a[end])
	return optimal(a,n-1,start+1,end,sum);

	return optimal(a,n-1,start,end-1,sum);
}

}

int main()
{
int n;
cin>>n;

int a[n];
for(int i=0;i<n;i++)
cin>>a[i];

cout<<optimal(a,n,0,n-1,0)<<endl;

}

@Nidhi_Alipuria,
Please use Coding Blocks IDE to share code, see how untidy it looks by just copy/pasting here.

You are doing correct in the case of piyush’s turn , but why did you chose greedily in his friends turn, just return min(optimal1,optimal2), cause when piyush’s friend will chose something that would benefit him the most, it would automatically mean that pixyish will get opposite of that, that is minimum.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.