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: 640 ms):
import java.util.*;

public class div2 {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int t = sc.nextInt();
        for(int i = 0 ; i<t ; i++){
            int n = sc.nextInt();

            int[] arr = new int[n];
            for(int j = 0 ; j < n ; j++){
                arr[j] = sc.nextInt();
            }

            int ind = 0;
            boolean flag = true;
            while(ind < n-1){
                if(arr[ind] <= arr[ind+1]){
                    arr[ind+1] -= arr[ind];
                    arr[ind] = 0;
                    ind++;
                }
                else {
                    flag = false;
                    break;
                }
            }
            if(!flag) System.out.println("NO");
            else System.out.println("YES");
        }
    }
}