Help me in solving PMA problem

My issue

why this code doesn’t work?

My code

import java.util.*;
import java.lang.*;
import java.io.*;

class Codechef
{
	public static void main (String[] args) throws java.lang.Exception
	{
		// your code goes here
        Scanner sc = new Scanner(System.in);
        int t = sc.nextInt();
        while(t-->0){
            int n = sc.nextInt();
            int[] a = new int[n/2 + n%2];
            int[] b = new int[n/2];
            int aa = 0, bb = 0;
            for(int i=0;i<n;){
                a[aa] =  sc.nextInt();
                if(a[aa]<0) a[aa]*=-1;
                aa++;
                i++;
                if(i<n){
                    b[bb] = sc.nextInt();
                    if(b[bb]<0) b[bb]*=-1;
                    bb++;
                }
                i++;
            }
            int sa =0,sb=0;
            for(int i=0;i<aa;i++)   sa+=a[i];
            for(int j=0;j<bb;j++)   sb+=b[j];
            Arrays.sort(a);
            Arrays.sort(b);
            int temp = a[0];
            a[0] = b[bb-1];
            b[bb-1] = temp;
            int suma = 0;
            int sumb = 0;
            for(int i=0;i<aa;i++)   suma+=a[i];
            for(int i=0;i<bb;i++)   sumb +=b[i];
            System.out.println(Math.max(sa-sb, suma - sumb));
        }
	}
}

Problem Link: Plusle and Minun on Array Practice Coding Problem - CodeChef

@santoon
plzz refer my c++ code

#include <bits/stdc++.h>
using namespace std;

int main() {
	// your code goes here
	int t;
	cin>>t;
	while(t--)
    {
        int n;
        cin>>n;
        long long int a[n];
        long long ans=0;
        long long int mx=INT_MIN;
        long long int mn=INT_MAX;
        for(int i=0;i<n;i++)
        {
            cin>>a[i];
            if(i%2==0)
            {
                mn=min(mn,abs(a[i]));
                ans+=abs(a[i]);
            }
            else
            {
                mx=max(mx,abs(a[i]));
                ans-=abs(a[i]);
            }
        }
        if(mn<mx)
        {
            ans-=mn;
            ans-=mn;
            ans+=mx;
            ans+=mx;
        }
        cout<<ans<<endl;
    }

}

I understand your code.
But what’s wrong with my code