Problem: 2063B - Subsequence Update
Language: java

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

/**
 * @Author: _Djhhh
 * @Introduction：
 */

public class Main {
    static FastReader fr = new FastReader();
    static FastWriter fw = new FastWriter();

    public static void solve() {
        int n=fr.nextInt();
        int l=fr.nextInt();
        int r=fr.nextInt();
        int[] arr = new int[n];
        int[] brr = new int[n];
        for(int i=0;i<n;i++){
            brr[i]=arr[i]= fr.nextInt();
        }
        Arrays.sort(arr,0,r);
        Arrays.sort(brr,l-1,n);
        long sum1=0;
        long sum2=0;
        for(int i=0;i<r-l+1;i++)sum1+=arr[i];
        for(int i=l-1;i<r;i++)sum2+=brr[i];
        fw.println(Math.min(sum1,sum2));
    }

    public static void main(String[] args) {
        int t = 1;
       t = fr.nextInt();
        while (t-- > 0) solve();
    }
}

class DSU {
    int n;
    int[] fa;
    int[] dep;
    int[] siz;
    int[] edges;
    boolean[] v;
    DSU(int n) {
        fa = new int[n];
        dep = new int[n];
        siz = new int[n];
        edges = new int[n];
        v = new boolean[n];
        for (int i = 0; i < n; i++) {
            fa[i] = i;
            dep[i] = 0;
            siz[i] = 1;
            edges[i] = 0;
            v[i]=false;
        }
    }
    int look(int x) {
        if (fa[x] == x) return x;
        else return fa[x] = look(fa[x]);
    }
    void merge(int x, int y) {
        v[x]=v[y]=true;
        int xx = look(x);
        int yy = look(y);
        if (xx == yy) return;
        edges[xx] += edges[yy] + 1;
        siz[xx] += siz[yy];
        if (dep[xx] < dep[yy]) {
            fa[xx] = yy;
        } else {
            fa[yy] = xx;
        }

        if (dep[xx] == dep[yy]) dep[xx]++;
    }
    boolean isMerge(int x, int y) {
        return look(x) == look(y);
    }
    int getSize(int x) {
        return siz[look(x)];
    }
    int getEdges(int x) {
        return edges[look(x)];
    }
}
class Pair<T1, T2> {
    private T1 first;
    private T2 second;

    public Pair(T1 first, T2 second) {
        this.first = first;
        this.second = second;
    }
    public void setFirst(T1 first) {
        this.first=first;
    }

    public void setSecond(T2 second) {
        this.second=second;
    }
    public T1 getFirst() {
        return first;
    }

    public T2 getSecond() {
        return second;
    }
}
class Algorithm {
    /**
     * 查找第一个大于等于 x 的位置
     * @param arr 查找数组
     * @param x 值
     * @param L 左边界
     * @param R 右边界
     * @return 第一个大于等于 x 的位置
     */
    public static int lowBs(int[] arr, long x, int L, int R){
        int l = L;
        int r = R;
        int res = R + 1;
        while(l <= r){
            int mid = l+r>>1;
            if(arr[mid] >= x){
                res = mid;
                r = mid - 1;
            }
            else{
                l = mid + 1;
            }
        }
        return res;
    }

    /**
     * 查找第一个大于 x 的位置
     * @param arr 查找数组
     * @param x 值
     * @param L 左边界
     * @param R 右边界
     * @return 第一个大于 x 的位置
     */
    public static int highBs(int[] arr, long x, int L, int R) {
        int l = L;
        int r = R;
        int res = R + 1;
        while(l <= r){
            int mid = l+r>>1;
            if(arr[mid] > x){
                res = mid;
                r = mid -1;
            }
            else{
                l = mid +1;
            }
        }
        return res;
    }
}
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 {
            str = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return str;
    }

    int[] nextIntArray() {
        String line = nextLine();
        String[] strNums = line.split("\\s+");
        int[] arr = new int[strNums.length];
        for (int i = 0; i < strNums.length; i++) {
            arr[i] = Integer.parseInt(strNums[i]);
        }
        return arr;
    }

    long[] nextLongArray() {
        String line = nextLine();
        String[] strNums = line.split("\\s+");
        long[] arr = new long[strNums.length];
        for (int i = 0; i < strNums.length; i++) {
            arr[i] = Long.parseLong(strNums[i]);
        }
        return arr;
    }

    char[] nextCharArray() {
        String line = nextLine();
        String[] strNums = line.split("\\s+");
        char[] arr = new char[strNums.length];
        for (int i = 0; i < strNums.length; i++) {
            arr[i] = strNums[i].charAt(0);
        }
        return arr;
    }

    char[] StringtoChar() {
        String line = nextLine();
        return line.toCharArray();
    }
}
class FastWriter {
    private final PrintWriter writer;

    public FastWriter() {
        writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)), true);
    }

    public void print(Object object) {
        writer.print(object);
    }

    public void println(Object object) {
        writer.println(object);
    }

    public void flush() {
        writer.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);
            }
        }
    }
}