# What's wrong in my logic/code for PMA problem from starters 29

my logic for was that i will swap the minimum element at even index with maximum element at odd element( 0- based indexing)
can someone tell me the testcase for which my code is failing and what should i do in order to correct it.

``````    #include"bits/stdc++.h"
#define ll long long int
#define MOD 1000000007
using namespace std;

int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
ll t;
cin>>t;
while(t--)
{
ll n;
cin>>n;
vector<ll> arr(n);
ll oddSum=0,evenSum=0;
ll maxOdd=INT_MIN,minEven=INT_MAX;
for(ll i=0;i<n;i++)
{
cin>>arr[i];
if(arr[i]<0)
{
arr[i]=abs(arr[i]);
}
if(i%2==0)
{
evenSum+=arr[i];
minEven=min(minEven,arr[i]);
}
else
{
oddSum+=arr[i];
maxOdd=max(arr[i],maxOdd);

}

}

evenSum=evenSum-minEven+maxOdd;
oddSum=oddSum-maxOdd+minEven;
cout<<evenSum-oddSum<<endl;

}
return 0;
}
``````

There can be a case when not swapping the two, will give the max sum
This is particularly when maxOdd < minEven, you can clearly see that swapping in this case will only decrease the even sum.

Test case:
8 2 11 5

Here max sum is 12 instead of 6

damn