Wrong answer on Submission
#include <bits/stdc++.h>
using namespace std;
int main() {
// your code goes here
int t;
cin >> t;
while (t--) {
int n ,f=1, sum=0;
cin >> n;
vector<int> a;
int mn = 1000000001 ,mx=-1 , index,indo;
for (int i=0;i<n;i++) {
int x; cin >> x;
a.push_back(abs(x));
}
for (int i=0;i<n;i++) {
if (i%2 == 1) {
mx=max(mx,a[i]);
if (a[i]==mx) indo = i;
}
}
for (int j=indo-1;j>=0;j-=2) {
mn = min(mn,a[j]);
if (a[j]==mn) index=j;
}
swap(a[index],a[indo]);
for (int i=0;i<n;i++) {
if (i%2==0) sum+=a[i];
else sum-=a[i];
//cout << a[i]<<' ';
}
cout <<sum<< endl;
}
}
problem link: https://www.codechef.com/practice/course/2-star-difficulty-problems/DIFF1500/problems/PMA