Problem: 2063B - Subsequence Update
Language: java

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

import java.util.*;



public class Code {



    // Input and Output

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

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



    // For parsing integers, longs, and strings efficiently

    static StringTokenizer st;



    // Entry point

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

        int t; // Number of test cases

        t = nextInt(); // Uncomment this line if multiple test cases

        while (t-- > 0) {

            solve(); // Call the solve function for each test case

        }

        out.close(); // Close the output stream

    }



    // Solve function for each test case



    static void solve() throws IOException {

        int n = nextInt();

        int l = nextInt();

        int r = nextInt();



        long[] arr = new long[n];



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

            arr[i] = nextLong();

        }

        long sum1 =0;

        long sum2 =0;



        long[] arr1 = new long[r];



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

            arr1[i] = arr[i];

        }

        sort(arr1);



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

            sum1 += arr1[i];

        }



        long[] arr2 = new long[n-l+1];



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

            arr2[i-l+1] = arr[i];

        }

        sort(arr2);



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

            sum2 += arr2[i];

        }



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

    }



    // Utility methods for faster input

    static String next() throws IOException {

        while (st == null || !st.hasMoreTokens()) {

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

        }

        return st.nextToken();

    }



    static int nextInt() throws IOException {

        return Integer.parseInt(next());

    }



    static long nextLong() throws IOException {

        return Long.parseLong(next());

    }



    static double nextDouble() throws IOException {

        return Double.parseDouble(next());

    }



    char nextChar() {

        try {

            return (char) br.read();

        } catch (IOException e) {

            e.printStackTrace();

            return '\0'; // Return null character in case of an error

        }

    }



    static String nextLine() throws IOException {

        return br.readLine();

    }



    // Utility functions

    static int gcd(int a, int b) {

        if (b == 0) return a;

        return gcd(b, a % b);

    }



    static int lcm(int a, int b) {

        return a * (b / gcd(a, b));

    }



    static boolean isPrime(int n) {

        if (n <= 1) return false;

        if (n <= 3) return true;

        if (n % 2 == 0 || n % 3 == 0) return false;

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

            if (n % i == 0 || n % (i + 2) == 0) return false;

        }

        return true;

    }



    static long power(long x, long y, long p) {

        long res = 1;

        x = x % p;

        while (y > 0) {

            if ((y & 1) == 1)

                res = (res * x) % p;

            y = y >> 1;

            x = (x * x) % p;

        }

        return res;

    }



    public static void sort(int[] arr)

    {

        //because Arrays.sort() uses quicksort which is dumb

        //Collections.sort() uses merge sort

        ArrayList<Integer> ls = new ArrayList<Integer>();

        for(int x: arr)

            ls.add(x);

        Collections.sort(ls);

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

            arr[i] = ls.get(i);

    }



    public static void sort(long[] arr)

    {

        //because Arrays.sort() uses quicksort which is dumb

        //Collections.sort() uses merge sort

        ArrayList<Long> ls = new ArrayList<Long>();

        for(long x: arr)

            ls.add(x);

        Collections.sort(ls);

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

            arr[i] = ls.get(i);

    }

}



Solution 2 (runtime: 281 ms):
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
// import java.math.BigInteger;
import java.util.*;

public class Yuv1 {

    public static boolean isPrime(int n) {
        if (n <= 1) {
            return false;
        }
        for (int i = 2; i <= Math.sqrt(n); i++) {
            if (n % i == 0) {
                return false;
            }
        }
        return true;
    }

    // GCD
    public static long gcd(long a, long b) {
        if (a == 0) {
            return b;
        }
        return gcd(b % a, a);
    }

    // Fast Input
    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(
                    new InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try {
                if (st.hasMoreTokens()) {
                    str = st.nextToken("\n");
                } else {
                    str = br.readLine();
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }

    public static long factorial(long n) {
        long f = 1;
        for (int i = 2; i <= n; i++)
            f *= i;
        return f;
    }

    public static long countDigitsInFact(long n) {

        if (n == 0 || n == 1) {
            return 1;
        }
        double logSum = 0;
        for (int i = 2; i <= n; i++) {
            logSum += Math.log10(i);
        }

        return (long) Math.floor(logSum) + 1;
    }
    private static void reverse(long[] arr, int start, int end) {
        while (start < end) {
            long temp = arr[start];
            arr[start] = arr[end];
            arr[end] = temp;
            start++;
            end--;
        }
    }

    private static long sumSubarray(long[] arr, int start, int end) {
        long sum = 0;
        for (int i = start; i <= end; i++) {
            sum += arr[i];
        }
        return sum;
    }

    public static int mod = 1000000007;
    static final long NEG_INF = -1000000000000000L;
    static final long INF = 1000000000000000L;

    public static void main(String args[]) {
        FastReader x = new FastReader();
        PrintWriter out = new PrintWriter(System.out);
        int t = x.nextInt();

        while (t-- > 0) {

            int n = x.nextInt();
            int l = x.nextInt();
            int r = x.nextInt();
            l--;
            long[] a = new long[n];
            for(int i=0;i<n;i++) {
                a[i]=x.nextLong();
            }

            long[] b = Arrays.copyOf(a, n);
            Arrays.sort(b, 0, r);
            reverse(b, 0, r-1);
            Arrays.sort(a, l, n);

            System.out.println(Math.min(sumSubarray(a, l, r-1), sumSubarray(b, l, r-1)));
        }
        out.flush();
    }
}