Problem: 2063B - Subsequence Update
Language: java

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

public class TestCodeforces
{
    public static void main(String[] args)
    {
        FastReader fr = new FastReader();
        PrintWriter pw = new PrintWriter(System.out);
        int t = fr.nextInt();
        while(t-->0)
        {
            int n = fr.nextInt();
            int l = fr.nextInt();
            int r = fr.nextInt();
            int wnd = r-l+1;
            long arr[] = new long[n];
            for(int i=0; i<n; i++)
            {   
                arr[i] = fr.nextInt();
            }   
            long min_sum = Math.min(sortSum(Arrays.copyOfRange(arr, 0, r), wnd), sortSum(Arrays.copyOfRange(arr, l-1, n), wnd));
            pw.println(min_sum);
        }
        pw.flush();
        pw.close();
    }

    public static long sortSum(long arr[], int z)
    {
        long sum = 0;
        Arrays.sort(arr);
        for(int i=0; i<z; i++)
        {
            sum += arr[i];
        }
        return sum;
    }
    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 {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }
    
    static public boolean isPrime(int n)
    {
        int z=0;
        for(int i=2; i<=n/2; i++)
        {
            if(n%i==0)
            {
                z++;
            }
        }
        if(z==1)
        {
            return true;
        }
        return false;
    }
    
    public static int gcd(int a, int b)
    {
        if (b == 0) return a;
        return gcd(b, a % b);
    }

}

Solution 2 (runtime: 453 ms):
import java.util.*;



public class B_Subsequence_Update{

    public static void main(String[] args) {

        Scanner s = new Scanner(System.in);

        int t = s.nextInt();

        while (t-->0){

            int n = s.nextInt();

            int l = s.nextInt();

            int r = s.nextInt();

            int[] arr = new int[n];

            for (int i=0;i<n;++i) arr[i] = s.nextInt();

            PriorityQueue<Integer> maxpq = new PriorityQueue<>((a,b)->b-a);

            PriorityQueue<Integer> minpql = new PriorityQueue<>();

            PriorityQueue<Integer> minpqr = new PriorityQueue<>();

            // ArrayList<Integer> raw = new ArrayList<>();

            long grr = 0;

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

                maxpq.add(arr[i]);

                grr += arr[i];

            }

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

            for (int i=r;i<n;++i) minpqr.add(arr[i]);

            long sw = 0, sol = 0, sor = 0;

            long ans = grr;

            while (!maxpq.isEmpty() && !minpql.isEmpty()){

                sw += maxpq.poll();

                sol += minpql.poll();

                ans = Math.min(ans,grr-sw+sol);

                // raw.add(sol);

                if (sol >= sw) break;

            }

            maxpq.clear();

            sw = 0;

            for (int i=l-1;i<r;++i) maxpq.add(arr[i]);

            while (!maxpq.isEmpty() && !minpqr.isEmpty()){

                sw += maxpq.poll();

                sor += minpqr.poll();

                ans = Math.min(ans,grr-sw+sor);

                // raw.add(sor);

                if (sor >= sw) break;

            }   

            System.out.println(ans);

        }

    }

}