Problem: 2060D - Subtract Min Sort
Language: java

Solution 1 (runtime: 312 ms):
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class prob {

    static class FastReader {
        BufferedReader b;
        StringTokenizer s;

        public FastReader() {
            b = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() {
            while (s == null || !s.hasMoreElements()) {
                try {
                    s = new StringTokenizer(b.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return s.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        float nextFloat() {
            return Float.parseFloat(next());
        }

        boolean nextBoolean() {
            return Boolean.parseBoolean(next());
        }

        // Method to read the next line as a string
        String nextLine() {
            String str = "";
            try {
                if (s == null || !s.hasMoreTokens()) {
                    str = b.readLine();
                } else {
                    str = s.nextToken("\n");
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }

    //===================================================================================================

    public static void main(String[] args) {
        FastReader fastReader = new FastReader();

        int t=0;
        t = fastReader.nextInt();

        while(t-- >0){
            int n = fastReader.nextInt();
            int[] arr = new int[n];

            for(int i=0;i<n;i++){
                arr[i] = fastReader.nextInt();
            }

            solve(arr, n);
        }
    }

    public static void solve(int[] arr, int n){

        for(int i=0;i<n-1;i++){
            int var = Math.min(arr[i], arr[i+1]);
            arr[i]-=var;
            arr[i+1]-=var;
        }

        for(int i=0;i<n-1;i++){
            if(arr[i+1]<arr[i]){
                System.out.println("NO");
                return;
            }
        }

        System.out.println("YES");
    }
}

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



public class Main {

    static  boolean check(int[] arr){

        for (int i = 0; i < arr.length-1; i++) {

            if (arr[i]>arr[i+1]) return  false;

        }

        return true;

    }

    public static void main(String[] args) {

        Scanner sc=new Scanner(System.in);

        int t = sc.nextInt();

        while(t-->0) {

            int n = sc.nextInt();

            int[] a =new int[n];

            for (int i = 0; i < n; i++) {

                a[i]= sc.nextInt();

            }

            boolean flag=false;

            int i =0;

            while (i< n-1){

                int min=Math.min(a[i],a[i+1]);

                a[i]=a[i]-min;

                a[i+1]=a[i+1]-min;

                i++;

            }

            if (check(a)) System.out.println("YES");

            else System.out.println("NO");

        }

    }

}