Problem: 2060D - Subtract Min Sort
Language: java

Solution 1 (runtime: 639 ms):
import java.util.*;

public class Main {
    public static void main(String[] args) {
      Scanner s=new Scanner(System.in);
      int t=s.nextInt();
      while(t-->0){
        int n=s.nextInt();
        int arr[]=new int[n];
        for(int i=0;i<n;i++){
          arr[i]=s.nextInt();
        }
        for(int i=1;i<n;i++){
          int a=Math.min(arr[i],arr[i-1]);
          arr[i-1]-=a;
          arr[i]-=a;
        }
        boolean ans=true;
        for(int i=0;i<n-1;i++){
          if(arr[i]!=0){
            ans=false;
            break;
          }
        }
        if(ans){
          System.out.println("YES");
        }else{
          System.out.println("NO");
        }
      }
  }
}

Solution 2 (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");
    }
}