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: 702 ms):
import java.util.*;
public class subtractminsort {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int t=sc.nextInt();
        for(int l=0;l<t;l++){
            int n=sc.nextInt();
            int arr[]=new int[n];
            for(int i=0;i<n;i++){
                arr[i]=sc.nextInt();
            }
            String res="YES";
            int a=Math.min(arr[0],arr[1]);
            arr[0]-=a;
            arr[1]-=a;
            if(arr[0]>arr[1]){
                res="NO";
            }
            if(res=="YES"){
                for(int i=1;i<n-1;i++){
                int min=Math.min(arr[i],arr[i+1]);
                arr[i]-=min;
                arr[i+1]-=min;
                if(arr[i-1]>arr[i]){
                    res="NO";
                    break;
                }
            }
            if(arr[n-2]>arr[n-1]){
                res="NO";
            }
        }
            System.out.println(res);
          
        }
        sc.close();
    }
}