Problem: 2063B - Subsequence Update
Language: java

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

        import java.util.*;



        public class Main {

            static class FastReader {

                BufferedReader br;

                StringTokenizer st;



                public FastReader() {

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

                }



                String next() {

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

                        try {

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

                        } catch (IOException e) {

                            e.printStackTrace();

                        }

                    }

                    return st.nextToken();

                }



                int nextInt() {

                    return Integer.parseInt(next());

                }



                int[] nextInts(int N) {

                    int[] res = new int[N];

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

                        res[i] = nextInt();

                    }

                    return res;

                }



                long nextLong() {

                    return Long.parseLong(next());

                }



                long[] nextLongs(int N) {

                    long[] res = new long[N];

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

                        res[i] = nextLong();

                    }

                    return res;

                }



                double nextDouble() {

                    return Double.parseDouble(next());

                }



                String nextLine() {

                    String str = "";

                    try {

                        str = br.readLine().trim();

                    } catch (IOException e) {

                        e.printStackTrace();

                    }

                    return str;

                }

            }



            static class FastWriter {

                private final BufferedWriter bw;

                private final StringBuilder sb;



                public FastWriter() {

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

                    this.sb = new StringBuilder();

                }



                public void print(Object object) {

                    sb.append(object);

                }



                public void println(Object object) {

                    sb.append(object).append("\n");

                }



                public void flush() throws IOException {

                    bw.write(sb.toString());

                    bw.flush();

                    sb.setLength(0);  // Clear StringBuilder

                }



                public void close() throws IOException {

                    flush();

                    bw.close();

                }

            }



            static FastReader sc = new FastReader();

            static FastWriter out = new FastWriter();



            static void solve() {



            

            int n  = sc.nextInt();

           long a[] = new long[n];

        int l  = sc.nextInt();

        int r  = sc.nextInt();

    



           for(int i=0;i<n;i++) a[i] = sc.nextLong();



           long b[] = new long[r-l+1];

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

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

        }

        Arrays.sort(b);



           Long ans = 0l;

        //    System.out.println(ans);



           PriorityQueue<Long> pq = new PriorityQueue<>();



        for(int i=0;i<l-1;i++) pq.add(a[i]);

        for(int i=b.length-1;i>=0;i--){

            if(pq.size()>0&&pq.peek()<b[i]){

                ans+=pq.poll();

            }

            else ans+=b[i];

        }

        pq.clear();

        for(int i=n-1;i>=r;i--){

            pq.add(a[i]);

        // System.out.println(a[i]);

        }

        long sm = 0;

          for(int i=b.length-1;i>=0;i--){

            if(pq.size()>0&&pq.peek()<b[i]){

                sm+=pq.poll();

            }

            else sm+=b[i];

        }







              System.out.println(Math.min(ans,sm)); 

        }







            static class pair{



                long f;

                long s;



                pair(long f,long s){

                    this.f=f;

                    this.s=s;

                    // this.t=t;

                }

            }



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

                int tc = sc.nextInt();

                // int tc=  1;

                while (tc-- > 0) {

                    solve();

                }

                out.close(); // Flush everything at the end

            }

    }



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