Problem: 2063B - Subsequence Update
Language: java

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

Solution 2 (runtime: 452 ms):
import java.util.Scanner;
public class Subsequence_Update{
    public static void merge(int[] arr, int l, int m, int r){
        int n1 = m - l + 1;
        int n2 = r - m;

        int[] L = new int[n1];
        int[] R = new int[n2];

        for(int i = 0; i<n1; i++){
            L[i] = arr[l + i];
        }

        for(int i = 0; i<n2; i++){
            R[i] = arr[m + 1 + i];
        }

        int i = 0;
        int j = 0;
        int k = l;

        while(i<n1 && j<n2){
            if(L[i] <= R[j]){
                arr[k] = L[i];
                i++;
            }else{
                arr[k] = R[j];
                j++;
            }
            k++;
        }

        while(i<n1){
            arr[k] = L[i];
            i++;
            k++;
        }

        while(j<n2){
            arr[k] = R[j];
            j++;
            k++;
        }
    }
    public static void mergeSort(int[] arr, int l, int r){
        if(l<r){
            int m = (l+r)/2;
            mergeSort(arr, l, m);
            mergeSort(arr, m+1, r);
            merge(arr, l, m, r);
        }
    }
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        Long t = sc.nextLong();
        for(int i = 0; i<t; i++){
            int n = sc.nextInt();
            long l = sc.nextLong();
            long r = sc.nextLong();
            int[] arr = new int[n];
            for(int j = 0; j<n; j++){
                arr[j] = sc.nextInt();
            }

            int[] arr1 = new int[(int) r];
            for(long j = 0; j<r; j++){
                arr1[(int)j] = arr[(int)j];
            }

            int[] arr2 = new int[(int)(n-l + 1)];
            for(int j = 0; j<n-l+1; j++){
                arr2[(int)j] = arr[(int)(j+l-1)];
            }

            mergeSort(arr1, 0, (int)(r-1));
            mergeSort(arr2, 0, (int)(n-l));

            Long sum1 = 0l;
            Long sum2 = 0l;

            for(int j = 0; j<(r - l + 1); j++){
                sum1 += arr1[j];
                sum2 += arr2[j];
            }

            if(sum1<=sum2){
                System.out.println(sum1);
            }else{
                System.out.println(sum2);
            }
        }
    }
}