ShaysXIA/CodeInsightBench huggingface dataset:
Problem: 2060D - Subtract Min Sort
Language: java

Solution 1 (runtime: 655 ms):
import java.util.*;
import java.lang.*;
import java.math.BigInteger;
import java.io.*;
public class cf{
    // public static long gcd(long a,long b){
    //     while(a!=0 && b!=0){
    //         if(a<b){
    //             b=b%a;
    //         }else{
    //             a=a%b;
    //         }
    //     }
    //     if(a!=0){
    //         return a;
    //     }else{
    //         return b;
    //     }
    // }  
    // public static long lcm(long a,long b){
    //     return (a/gcd(a,b))*b;
    // }

    public static void main(String args[]){
        Scanner sc=new Scanner(System.in);
        int tsts=sc.nextInt();
        for(int t=0;t<tsts;t++){
            int n=sc.nextInt();
            // int k=sc.nextInt();
            // int a4=sc.nextInt();
            // int a5=sc.nextInt();
            // int r2=sc.nextInt();
            // StringBuilder s=new StringBuilder(sc.next());
            // String a=sc.next();
            // String b=sc.next();
            // String c=sc.next();
            int[] a=new int[n];
            for(int i=0;i<n;i++){
                a[i]=sc.nextInt();
            }
            // int[] b=new int[n];
            // for(int i=0;i<n;i++){
            //     b[i]=sc.nextInt();
            // }
            // long n=sc.nextLong();
            // long k=sc.nextLong();
            // long r=sc.nextInt();
            // long c=sc.nextInt();
            for(int i=0;i<n-1;i++){
                int temp=Math.min(a[i],a[i+1]);
                a[i]-=temp;
                a[i+1]-=temp;
            }
            int[] b=new int[n];
            for(int i=0;i<n;i++){
                b[i]=a[i];
            }
            Arrays.sort(b);
            boolean flag=true;
            for(int i=0;i<n;i++){
                if(a[i]!=b[i]){
                    flag=false;
                    break;
                }
            }
            if(flag) System.out.println("Yes");
            else System.out.println("No");
        }    
    }
}

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");

        }

    }

}
Problem: 2063B - Subsequence Update
Language: java

Solution 1 (runtime: 327 ms):
import java.io.*;

import java.util.*;



public class Main {

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



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

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



        if (System.getProperty("ONLINE_JUDGE") == null) {

            br = new BufferedReader(new FileReader("src/Input.txt"));

            bw = new BufferedWriter(new FileWriter("src/Output.txt"));

        }



        // Your code here



        int t = Integer.parseInt(br.readLine());

        while(t --> 0) {

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

            int n = Integer.parseInt(st.nextToken());

            int l = Integer.parseInt(st.nextToken())-1;

            int r = Integer.parseInt(st.nextToken())-1;



            long[] arr =new long[n];

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

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

                arr[i] = Long.parseLong(st.nextToken());

            }



            // [0,r] [l,n-1]

            long[] left = Arrays.copyOfRange(arr, 0, r+1);

            long[] right = Arrays.copyOfRange(arr, l, n);



            Arrays.sort(left);

            Arrays.sort(right);



            long leftSum = 0;

            long rightSum = 0;

            int k = r-l+1;

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

                leftSum += left[i];

            }

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

                rightSum += right[i];

            }



            bw.write(Math.min(leftSum, rightSum) + "\n");

        }



        bw.flush();

        br.close();

        bw.close();

    }

}

Solution 2 (runtime: 467 ms):
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

public class SubsequenceUpdate {
  public static void main(String[] args){
    Scanner scanner = new Scanner(System.in);
    int tests = Integer.parseInt(scanner.nextLine());
    while (tests > 0){
      int n = scanner.nextInt();
      int l = scanner.nextInt();
      int r = scanner.nextInt();
      long[] arr = new long[n];
      for (int i = 0; i < arr.length; i++){
        arr[i] = scanner.nextLong();
      }

      ArrayList<Long> toL = new ArrayList<>();
      ArrayList<Long> toR = new ArrayList<>();
      for (int i = 0; i < r; i++){
        toR.add(arr[i]);
      }
      for (int i = l - 1; i < n; i++){
        toL.add(arr[i]);
      }

      Collections.sort(toL);
      Collections.sort(toR);

      long sumOne = 0;
      for (int i = 0; i < r - l + 1; i++){
        sumOne += toL.get(i);
      }

      long sumTwo = 0;
      for (int i = 0; i < r - l + 1; i++){
        sumTwo += toR.get(i);
      }

      System.out.println(Math.min(sumTwo, sumOne));
      tests--;
    }
  }
}
Problem: 2060D - Subtract Min Sort
Language: java

Solution 1 (runtime: 655 ms):
import java.util.*;
import java.lang.*;
import java.math.BigInteger;
import java.io.*;
public class cf{
    // public static long gcd(long a,long b){
    //     while(a!=0 && b!=0){
    //         if(a<b){
    //             b=b%a;
    //         }else{
    //             a=a%b;
    //         }
    //     }
    //     if(a!=0){
    //         return a;
    //     }else{
    //         return b;
    //     }
    // }  
    // public static long lcm(long a,long b){
    //     return (a/gcd(a,b))*b;
    // }

    public static void main(String args[]){
        Scanner sc=new Scanner(System.in);
        int tsts=sc.nextInt();
        for(int t=0;t<tsts;t++){
            int n=sc.nextInt();
            // int k=sc.nextInt();
            // int a4=sc.nextInt();
            // int a5=sc.nextInt();
            // int r2=sc.nextInt();
            // StringBuilder s=new StringBuilder(sc.next());
            // String a=sc.next();
            // String b=sc.next();
            // String c=sc.next();
            int[] a=new int[n];
            for(int i=0;i<n;i++){
                a[i]=sc.nextInt();
            }
            // int[] b=new int[n];
            // for(int i=0;i<n;i++){
            //     b[i]=sc.nextInt();
            // }
            // long n=sc.nextLong();
            // long k=sc.nextLong();
            // long r=sc.nextInt();
            // long c=sc.nextInt();
            for(int i=0;i<n-1;i++){
                int temp=Math.min(a[i],a[i+1]);
                a[i]-=temp;
                a[i+1]-=temp;
            }
            int[] b=new int[n];
            for(int i=0;i<n;i++){
                b[i]=a[i];
            }
            Arrays.sort(b);
            boolean flag=true;
            for(int i=0;i<n;i++){
                if(a[i]!=b[i]){
                    flag=false;
                    break;
                }
            }
            if(flag) System.out.println("Yes");
            else System.out.println("No");
        }    
    }
}

Solution 2 (runtime: 640 ms):
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int t = sc.nextInt();

        outer :
        while(t>0){
            int n = sc.nextInt();

            int[] nums = new int[n];

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

            for(int i = 1 ; i < n ; i++){
                int min = Math.min(nums[i],nums[i-1]);
                nums[i] = nums[i] - min;
                nums[i-1] = nums[i-1] - min;

                if(nums[i-1] > nums[i] ) {
                    System.out.println("NO");
                    t--;
                    continue outer;
                }
            }
            System.out.println("YES");
            t--;
        }
    }
}
Problem: 2063B - Subsequence Update
Language: java

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

import java.io.*;

public class MooCounting {

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

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

        int t = Integer.parseInt(br.readLine());



        while(t-- > 0)

        {

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

            int n = Integer.parseInt(st.nextToken());

            int left = Integer.parseInt(st.nextToken());

            left--;

            int right = Integer.parseInt(st.nextToken());

            right--;

            long k = (long)right - (long)left + 1;



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

            int[] arr = new int[n];

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

            {

                arr[i] = Integer.parseInt(st.nextToken());

            }



            // Case 1: [l, n]

            int[] option1 = Arrays.copyOfRange(arr, left, n);

            Arrays.sort(option1);

            long sum1 = 0;

            for (int i = 0; i < k; i++) sum1 += option1[i];



            // Case 2: [1, r]

            int[] option2 = Arrays.copyOfRange(arr, 0, right + 1);

            Arrays.sort(option2);

            long sum2 = 0;

            for (int i = 0; i < k; i++) sum2 += option2[i];



            

            System.out.println(Math.min(sum1, sum2)); 

        }

    }

}

Solution 2 (runtime: 280 ms):
// Problem Page: https://codeforces.com/contest/2063/problem/B



import java.util.*;



public class SubsequenceUpdate {



    public static void main(String[] args) {



        Scanner sc = new Scanner(System.in);

        int t = sc.nextInt();

        while (t-- > 0) {

            solve(sc);

        }

    }



    //subsequence does not have to be contiguous

    static void solve(Scanner sc) {

        int n = sc.nextInt();

        int l = sc.nextInt();

        int r = sc.nextInt();

        int[] a = new int[n];

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

            a[i] = sc.nextInt();

        }

        int[] b = new int[r];

        int[] c = new int[n - l + 1];

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

            b[i] = a[i];

        }

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

            c[i - l + 1] = a[i];

        }

        Arrays.sort(b);

        Arrays.sort(c);

        long sum_b = 0, sum_c = 0;

        for (int i = 0; i <= (r - l); i++) {

            sum_b += b[i];

            sum_c += c[i];

        }

        System.out.println(Math.min(sum_b, sum_c));

    }

}
Problem: 2060D - Subtract Min Sort
Language: java

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

public class question {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int t = sc.nextInt();

        while (t-- > 0) {
            int n = sc.nextInt();

            int[] arr = new int[n];

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

            int help = 0 ;

            for(int i = 0 ; i < n-1 ; i++){
                int a = arr[i];
                int b = arr[i+1];

                if(a > b){
                    System.out.println("NO");
                    help++;
                    break;
                }else{

                    arr[i+1] = arr[i+1] - arr[i];
                    arr[i] = 0 ;
                    //System.out.println(arr[i+1]);
                }
            }


            if(help == 0){
                System.out.println("YES");
            }

        }
    }
}


Solution 2 (runtime: 656 ms):
import java.util.*;

public class Main{

public static void main(String args[]){

Scanner scanner = new Scanner(System.in);

int tests = scanner.nextInt();

while(tests-- > 0){

int n = scanner.nextInt();

int A[] = new int[n];

boolean flag = false;

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

A[i] = scanner.nextInt();

}

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

if(A[i] > A[i + 1]){

flag = true;

break;

}else{

int temp = A[i];

A[i] -= temp;

A[i + 1] -= temp;

}

}

if(!flag){

System.out.println("YES");

}else{

System.out.println("NO");

}

}

scanner.close();

}



}
Problem: 2060D - Subtract Min Sort
Language: java

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

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int t = sc.nextInt();

        outer :
        while(t>0){
            int n = sc.nextInt();

            int[] nums = new int[n];

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

            for(int i = 1 ; i < n ; i++){
                int min = Math.min(nums[i],nums[i-1]);
                nums[i] = nums[i] - min;
                nums[i-1] = nums[i-1] - min;

                if(nums[i-1] > nums[i] ) {
                    System.out.println("NO");
                    t--;
                    continue outer;
                }
            }
            System.out.println("YES");
            t--;
        }
    }
}

Solution 2 (runtime: 686 ms):
import java.util.*;



public class mywork {

public static boolean isPrime(int n) {

if (n <= 1) {

return false;

}

for (int i = 2; i * i <= n; i++) {

if (n % i == 0) {

return false;

}

}

return true;

}

public static void main(String[] args) {

Scanner sc = new Scanner(System.in);

long T = sc.nextLong();

while (T-- > 0) {

int N = sc.nextInt();

int A[] = new int[N];

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

A[i] = sc.nextInt();

}

int flag = 0;

for(int i = 0;i<N-1;i++){

if(A[i+1]<A[i]){

flag=1;

break;

}

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

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

A[i]= A[i]-min;

}

if(flag==1){

System.out.println("NO");

}else{

System.out.println("YES");

}



}

}

}
Problem: 2062C - Cirno and Operations
Language: java

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

public class Main {
    static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    static StringTokenizer st;

    public static String next() throws IOException {
        while (st == null || !st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }
    public static int nextLong() throws IOException {
        return Integer.parseInt(next());
    }

    public static int nextInt() throws IOException {
        return Integer.parseInt(next());
    }

    public static void main(String[] args) throws IOException {
        int t = nextInt();
        while (t-- > 0) {
            run();
        }
    }

    public static void run() throws IOException {
        int n = nextInt();
        long[] arr = new long[n];
        int new_len = n;
        for(int i = 0;i<n;i++){
            arr[i] = nextLong();
        }
        long min = Long.MIN_VALUE;
        for(int i = 0;i<n;i++){
            long sum = 0;
            for(int j=0;j<new_len;j++){
                sum+=arr[j];
            }
            if(i==0){
                min = Math.max(min,sum);
            }
            else{
                min = Math.max(min,Math.max(sum,-sum));
            }
            for(int j = 0;j<n-1;j++){
                arr[j] = arr[j+1]-arr[j];
            }
            new_len--;
        }
        System.out.println(min);
    }
}


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

public class C_Cirno_and_Operations {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int t = sc.nextInt();
        while (t-->0) {
            int n = sc.nextInt();
            long[] arr = new long[n+1];
            for (int i=1; i<=n; i++) {
                arr[i] = sc.nextLong();
            }
            int curr = n;
            long ans = Long.MIN_VALUE;
            for (int i=1; i<=n; i++) {
                long sum = 0;
                for (int j=1; j<=curr; j++) {
                    sum += arr[j];
                }
                if (i==1) {
                    ans = Math.max(ans, sum);
                }
                else ans = Math.max(ans, Math.max(sum,-sum));
                for (int j=1; j<curr; j++) {
                    arr[j] = arr[j+1]-arr[j];
                }
                curr--;
            }
            System.out.println(ans);
        }
        sc.close();
    }
}
Problem: 2063B - Subsequence Update
Language: java

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

public final class F1{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int t = sc.nextInt();
		while(t-- != 0){
			int n = sc.nextInt();
			int l = sc.nextInt();
			int r = sc.nextInt();
			int[] arr = new int[n];
			int[] left = new int[r];
			int[] right = new int[n-l+1];
			for(int i = 0; i < arr.length; i++){
				arr[i] = sc.nextInt();
			}
			for(int i = 0; i < left.length; i++){
				left[i] = arr[i];
			}
			for(int i = 0; i < right.length; i++){
				right[i] = arr[l-1+i];
			}
			Arrays.sort(left);
			Arrays.sort(right);
			long sum1 = 0;
			long sum2 = 0; 
			for(int i = 0 ; i <= r - l; i++){
				sum1 += (long)left[i];
				sum2 += (long)right[i];
			}
			System.out.println(Math.min(sum1, sum2));
		}
	}		
}

Solution 2 (runtime: 327 ms):
import java.io.*;

import java.util.*;



public class Main {

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



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

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



        if (System.getProperty("ONLINE_JUDGE") == null) {

            br = new BufferedReader(new FileReader("src/Input.txt"));

            bw = new BufferedWriter(new FileWriter("src/Output.txt"));

        }



        // Your code here



        int t = Integer.parseInt(br.readLine());

        while(t --> 0) {

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

            int n = Integer.parseInt(st.nextToken());

            int l = Integer.parseInt(st.nextToken())-1;

            int r = Integer.parseInt(st.nextToken())-1;



            long[] arr =new long[n];

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

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

                arr[i] = Long.parseLong(st.nextToken());

            }



            // [0,r] [l,n-1]

            long[] left = Arrays.copyOfRange(arr, 0, r+1);

            long[] right = Arrays.copyOfRange(arr, l, n);



            Arrays.sort(left);

            Arrays.sort(right);



            long leftSum = 0;

            long rightSum = 0;

            int k = r-l+1;

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

                leftSum += left[i];

            }

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

                rightSum += right[i];

            }



            bw.write(Math.min(leftSum, rightSum) + "\n");

        }



        bw.flush();

        br.close();

        bw.close();

    }

}
Problem: 2063B - Subsequence Update
Language: java

Solution 1 (runtime: 452 ms):
import java.util.*;
public class Main{
  public static void main(String []args){
    Scanner sc = new Scanner(System.in);
    int t =sc.nextInt();
    while(t-- > 0){
      int n = sc.nextInt();
      int l = sc.nextInt();
      int r = sc.nextInt();
      l--;
      r--;
      int []arr = new int[n];
      for(int i = 0; i < n; i++){
        arr[i] = sc.nextInt();
      }
      List<Integer> left = new ArrayList<>();
      for(int i = 0; i <= r; i++)left.add(arr[i]);
      List<Integer> right = new ArrayList<>();
      for(int i = l; i < n; i++)right.add(arr[i]);
      Collections.sort(left);
      Collections.sort(right);
      long j = 0;
      long h = 0;
      for(int i = 0; i < r-l+1; i++){
        j += (long)left.get(i);
        h += (long)right.get(i);
      }
      System.out.println(Math.min(j,h));
    }
      
    }
}

Solution 2 (runtime: 281 ms):
import java.util.*;

import java.io.*;

public class MooCounting {

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

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

        int t = Integer.parseInt(br.readLine());



        while(t-- > 0)

        {

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

            int n = Integer.parseInt(st.nextToken());

            int left = Integer.parseInt(st.nextToken());

            left--;

            int right = Integer.parseInt(st.nextToken());

            right--;

            long k = (long)right - (long)left + 1;



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

            int[] arr = new int[n];

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

            {

                arr[i] = Integer.parseInt(st.nextToken());

            }



            // Case 1: [l, n]

            int[] option1 = Arrays.copyOfRange(arr, left, n);

            Arrays.sort(option1);

            long sum1 = 0;

            for (int i = 0; i < k; i++) sum1 += option1[i];



            // Case 2: [1, r]

            int[] option2 = Arrays.copyOfRange(arr, 0, right + 1);

            Arrays.sort(option2);

            long sum2 = 0;

            for (int i = 0; i < k; i++) sum2 += option2[i];



            

            System.out.println(Math.min(sum1, sum2)); 

        }

    }

}