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: 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

            }

    }