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: 499 ms):
import java.util.*;

public class Main
{
	public static void main(String[] args) {
		int t;
		Scanner sc = new Scanner(System.in);
		t = sc.nextInt();
		while(t > 0){
		    int n = sc.nextInt();
		    int l = sc.nextInt();
		    int r = sc.nextInt();
		    l--;
		    r--;
		    List<Integer> arr1 = new ArrayList<>();
		    List<Integer> arr2 = new ArrayList<>();
		    List<Integer> arr3 = new ArrayList<>();
		    for (int i = 0; i < l; i++){
		        arr1.add(sc.nextInt());
		    }
		    for (int i = l; i <= r; i++){
		        arr2.add(sc.nextInt());
		    }
		    for (int i = r + 1; i < n; i++){
		        arr3.add(sc.nextInt());
		    }
		    Collections.sort(arr1);
		    Collections.sort(arr2);
		    Collections.sort(arr3);
		  //  System.out.println(arr1);
		  //  System.out.println(arr2);
		  //  System.out.println(arr3);
		    long sum1 = 0, sum2 = 0;
		    int j = 0;
		    for (int i = arr2.size() - 1; i >= 0; i--){
		        int num1 = arr2.get(i);
		        if (j < arr1.size()){
		            num1 = Math.min(num1, arr1.get(j));
		            j++;
		        }
		        sum1 += num1;
		    }
		    j = 0;
		    for (int i = arr2.size() - 1; i >= 0; i--){
		        int num1 = arr2.get(i);
		        if (j < arr3.size()){
		            num1 = Math.min(num1, arr3.get(j));
		            j++;
		        }
		        sum2 += num1;
		    }
		    long ans = Math.min(sum1, sum2);
		    System.out.println(ans);
		    t--;
		}
	}
}