Maximum value Div 3 problem (https://www.codechef.com/START1C/problems/MVALUE)

This paased sample test case but not accepted by online judge . plz tell me what is wrong with this code

#include

#include

using namespace std;

int main()

{

ios_base::sync_with_stdio(false);

cin.tie(NULL);

long long t;

cin>>t;

while(t--)

{

    long long n;

    cin>>n;

    long long arr[n];

    for(long long i=0;i<n;i++)

    {

        cin>>arr[i];

    }

    long long ans=0,maxi=0,max1=0,res;

    for(long long i=0;i<n-1;i++)

    {

        

         long long ans = arr[i]*arr[i+1]+max((arr[i]-arr[i+1]),(arr[i+1]-arr[i]));

         maxi = max(maxi,ans);

    }

 

    res = (arr[0]*arr[n-1])+max((arr[0]-arr[n-1]),(arr[n-1]-arr[0]));

   

    max1 = max(maxi,res);

    cout<<max1<<"\n";

}

}

well i think you are only checking for adjacent elements. Check the editorial for clarification.
for a test case like 5 3 4 2, your code will not check the pair 4, 5, which is indeed the greatest pair here.

Understood Bro . Can u share your code

My Solution : CodeChef: Practical coding for everyone
this^ is the most efficient solution(i think).
Check the editorial : MVALUE - Editorial
for further clarification (including video solution)