Help me in solving P4149 problem

My issue

What will be the output of the array [-3, 4, 5, 2, 1] according to this problem?

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];
            int cnt = 0;
            long sum = 0;
            int p = Integer.MAX_VALUE;
            for(int i =0; i<n; i++) {
                a[i] = sc.nextInt();
                sum += Math.abs(a[i]);
                p = Math.min(p, Math.abs(a[i]));
                if(a[i] < 0) {
                    // p = Math.max(p, a[i]);
                    cnt++;
                }
            }
            
            if(cnt%2 != 0) {
                    sum += p*2;
            }
            
            System.out.println(sum);
        }
        sc.close();

	}
}

Problem Link: Maximise Sum Practice Coding Problem