Problem: 2062C - Cirno and Operations
Language: java

Solution 1 (runtime: 218 ms):
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Olynpiade3 {
    static FastScanner scan = new FastScanner(new InputStreamReader(System.in));
    public static void main(String[] args) {
        int t = scan.nextInt();
        for (int i = 0; i < t; i++)
            solve();
    }
    static void solve(){
        int n = scan.nextInt();
        long[] posl = new long[n];
        posl[0] = scan.nextInt();
        int pos;
        long sum1 = 0, sum2 = 0, max = posl[0];
        for (int i = 1; i < n; i++){
            posl[i] = scan.nextInt();
            max += posl[i];
            sum1 += posl[i] - posl[i-1];
            sum2 += posl[i-1] - posl[i];
        }
        //System.out.println(Arrays.toString(posl) + " " + sum1 + " " + sum2 + " " + max);
        int znak;
        long sum;
        for (int i = 0; i < n - 1; i++){
            pos = 1;
            if (sum1 > sum2){
                znak = 1;
            }else
                znak = -1;
            posl[0] = (long) znak * (posl[1] - posl[0]);
            sum1 = 0; sum2 = 0; sum = posl[0];
            if (n - 1 >= 2)
                while (pos != n - i - 1){
                    pos++;
                    posl[pos - 1] = (long) znak * (posl[pos] - posl[pos-1]);
                    sum += posl[pos - 1];
                    sum1 += posl[pos - 1] - posl[pos - 2];
                    sum2 += posl[pos - 2] - posl[pos - 1];
                    //System.out.println(Arrays.toString(posl));
                }

            if (sum > max)
                max = sum;
            //System.out.println(Arrays.toString(posl));
        }
        System.out.println(max);
    }
}


class FastScanner

{

    private BufferedReader br;

    private StringTokenizer st;



    public FastScanner(InputStreamReader reader)

    {

        br = new BufferedReader(reader);

    }



    public String next()

    {

        while (st == null || !st.hasMoreTokens())

        {

            try

            {

                st = new StringTokenizer(br.readLine());

            } catch (Exception e)

            {

                e.printStackTrace();

            }

        }

        return st.nextToken();

    }



    public int nextInt()

    {

        return Integer.parseInt(next());

    }



    public double nextDouble()

    {

        return Double.parseDouble(next());

    }



    public void close() throws Exception

    {

        br.close();

    }

}

Solution 2 (runtime: 296 ms):
import java.util.Scanner;

public class C_Cirno_and_Operations {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int t = sc.nextInt();
        while (t-->0) {
            int n = sc.nextInt();
            long[] arr = new long[n+1];
            for (int i=1; i<=n; i++) {
                arr[i] = sc.nextLong();
            }
            int curr = n;
            long ans = Long.MIN_VALUE;
            for (int i=1; i<=n; i++) {
                long sum = 0;
                for (int j=1; j<=curr; j++) {
                    sum += arr[j];
                }
                if (i==1) {
                    ans = Math.max(ans, sum);
                }
                else ans = Math.max(ans, Math.max(sum,-sum));
                for (int j=1; j<curr; j++) {
                    arr[j] = arr[j+1]-arr[j];
                }
                curr--;
            }
            System.out.println(ans);
        }
        sc.close();
    }
}