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: 312 ms):
import java.util.*;
public class cirnoop2
{
   public static void main(String args[])
   {
       Scanner in = new Scanner(System.in);
       int t=in.nextInt();
       while(t!=0)
       {
           t--;
           int n=in.nextInt();
           long arr[]=new long[n];
           int i,j;
           long s=0,max=0;
           
           for(i=0;i<n;i++)
           {
               arr[i]=in.nextInt();
               s=s+arr[i];
           }
           if(n==1)
           {
               System.out.println(arr[0]);
           }          
           else
           {
           
           max=Math.max(s,-(long)Math.pow(10,18));
           while(n>=1)
           {
               
               
               --n;
               
               s=0;
               
               for(i=0;i<n;i++)
               {
                   arr[i]=arr[i+1]-arr[i];
                   s=s+arr[i];
               }
               arr[n]=0;
               
              
               s=Math.abs(s);
               max=Math.max(s,max);
           }
           System.out.println(max);
           }
           
   }
}
}