Problem: 2063B - Subsequence Update
Language: java

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

public class Solution {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int t = sc.nextInt();  // number of test cases
        while (t-- > 0) {
            // Read n, l, r
            int n = sc.nextInt();
            int l = sc.nextInt();  // 1-based index
            int r = sc.nextInt();  // 1-based index

            // Read array arr
            long[] arr = new long[n + 1];  // Using long[] for larger values, and n+1 to handle 1-based indexing
            for (int i = 1; i <= n; i++) {
                arr[i] = sc.nextLong();
            }

            // Step 1: Calculate the sum for the range [l, r]
            long initialSum = 0;
            for (int i = l; i <= r; i++) {
                initialSum += arr[i];
            }
            long min = initialSum;  // Store the initial sum as the minimum

            // Step 2: Find the smallest `r - l + 1` elements from [1, r]
            List<Long> prefix = new ArrayList<>();
            for (int i = 1; i <= r; i++) {
                prefix.add(arr[i]);
            }
            Collections.sort(prefix);
            long prefixSum = 0;
            // Sum the smallest `r - l + 1` elements from the sorted prefix
            for (int i = 0; i < r - l + 1; i++) {
                prefixSum += prefix.get(i);
            }
            min = Math.min(min, prefixSum);  // Update the minimum sum

            // Step 3: Find the smallest `r - l + 1` elements from [l, n]
            List<Long> suffix = new ArrayList<>();
            for (int i = l; i <= n; i++) {
                suffix.add(arr[i]);
            }
            Collections.sort(suffix);
            long suffixSum = 0;
            // Sum the smallest `r - l + 1` elements from the sorted suffix
            for (int i = 0; i < r - l + 1; i++) {
                suffixSum += suffix.get(i);
            }
            min = Math.min(min, suffixSum);  // Update the minimum sum

            // Output the result for the current test case
            System.out.println(min);
        }
    }
}


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