Problem: 2060D - Subtract Min Sort
Language: Java 21

Previous submission (verdict: Wrong answer on test 2):
import java.io.*;

import java.math.*;

import java.util.*;



public class Main {

static class IoScanner {

BufferedReader bf;

StringTokenizer st;

BufferedWriter bw;



public IoScanner() {

bf = new BufferedReader(new InputStreamReader(System.in));

st = new StringTokenizer("");

bw = new BufferedWriter(new OutputStreamWriter(System.out));

}



public String nextLine() throws IOException {

return bf.readLine();

}



public String next() throws IOException {

while (!st.hasMoreTokens()) {

st = new StringTokenizer(bf.readLine());

}

return st.nextToken();

}



public char nextChar() throws IOException {

return next().charAt(0);

}



public int nextInt() throws IOException {

return Integer.parseInt(next());

}



public long nextLong() throws IOException {

return Long.parseLong(next());

}



public double nextDouble() throws IOException {

return Double.parseDouble(next());

}



public float nextFloat() throws IOException {

return Float.parseFloat(next());

}



public BigInteger nextBigInteger() throws IOException {

return new BigInteger(next());

}



public BigDecimal nextDecimal() throws IOException {

return new BigDecimal(next());

}

}

static IoScanner sc = new IoScanner();

static PrintWriter out = new PrintWriter(System.out);

static final int mod=(int) (1e9+7);

public static void main(String[] args) throws Exception {

int T = 1;

T = sc.nextInt();

while (T-- > 0) {

solve();

}

out.flush();

}

static void solve() throws IOException {

int n=sc.nextInt();

int[] arr = new int[n];

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

arr[i]=sc.nextInt();

}

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

if (arr[i - 1] < arr[i]) {

arr[i]-=arr[i-1];

arr[i-1]=0;

}

}

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

if (arr[i - 1] > arr[i]) {

out.println("NO");

return;

}

}

out.println("YES");

}

}



Submission (verdict: Accepted):
import java.io.*;

import java.math.*;

import java.util.*;



public class Main {

static class IoScanner {

BufferedReader bf;

StringTokenizer st;

BufferedWriter bw;



public IoScanner() {

bf = new BufferedReader(new InputStreamReader(System.in));

st = new StringTokenizer("");

bw = new BufferedWriter(new OutputStreamWriter(System.out));

}



public String nextLine() throws IOException {

return bf.readLine();

}



public String next() throws IOException {

while (!st.hasMoreTokens()) {

st = new StringTokenizer(bf.readLine());

}

return st.nextToken();

}



public char nextChar() throws IOException {

return next().charAt(0);

}



public int nextInt() throws IOException {

return Integer.parseInt(next());

}



public long nextLong() throws IOException {

return Long.parseLong(next());

}



public double nextDouble() throws IOException {

return Double.parseDouble(next());

}



public float nextFloat() throws IOException {

return Float.parseFloat(next());

}



public BigInteger nextBigInteger() throws IOException {

return new BigInteger(next());

}



public BigDecimal nextDecimal() throws IOException {

return new BigDecimal(next());

}

}

static IoScanner sc = new IoScanner();

static PrintWriter out = new PrintWriter(System.out);

static final int mod=(int) (1e9+7);

public static void main(String[] args) throws Exception {

int T = 1;

T = sc.nextInt();

while (T-- > 0) {

solve();

}

out.flush();

}

static void solve() throws IOException {

int n=sc.nextInt();

int[] arr = new int[n];

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

arr[i]=sc.nextInt();

}

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

if (arr[i - 1] > arr[i]) {

out.println("NO");

return;

}else {

arr[i] -= arr[i - 1];

arr[i-1]=0;

}

}

out.println("YES");

}

}