Problem: 2063B - Subsequence Update
Language: java

Solution 1 (runtime: 452 ms):
import java.util.*;
public class Main{
  public static void main(String []args){
    Scanner sc = new Scanner(System.in);
    int t =sc.nextInt();
    while(t-- > 0){
      int n = sc.nextInt();
      int l = sc.nextInt();
      int r = sc.nextInt();
      l--;
      r--;
      int []arr = new int[n];
      for(int i = 0; i < n; i++){
        arr[i] = sc.nextInt();
      }
      List<Integer> left = new ArrayList<>();
      for(int i = 0; i <= r; i++)left.add(arr[i]);
      List<Integer> right = new ArrayList<>();
      for(int i = l; i < n; i++)right.add(arr[i]);
      Collections.sort(left);
      Collections.sort(right);
      long j = 0;
      long h = 0;
      for(int i = 0; i < r-l+1; i++){
        j += (long)left.get(i);
        h += (long)right.get(i);
      }
      System.out.println(Math.min(j,h));
    }
      
    }
}

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

            }

    }