2063B - B. Subsequence Update

import java.util.Queue;
import java.util.Scanner;
 
public class App {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int cases = Integer.parseInt(sc.nextLine());
        Queue<Integer> pq1 = new PriorityQueue<>();
        Queue<Integer> pq2 = new PriorityQueue<>();
        for (int i = 0; i < cases; ++i) {
            pq1.clear();
            pq2.clear();
            int n = sc.nextInt();
            int l = sc.nextInt();
            int r = sc.nextInt();
            sc.nextLine();
            int[] arr = new int[n];
            for (int j = 0; j < n; ++j)  {
                arr[j] = sc.nextInt();
                if (j >= l - 1) {
                    pq1.offer(arr[j]);
                }
                if (j <= r - 1) {
                    pq2.offer(arr[j]);
                }  
            }
 
            long sum1 = 0, sum2 = 0;
            for (int j = 0; j <= r - l; ++j) {
                sum1 += pq1.poll();
                sum2 += pq2.poll();
            }
            System.out.println(Math.min(sum1, sum2));
        }
        sc.close();
    }
}
posted @ 2025-03-26 15:29  kayaker  阅读(21)  评论(0)    收藏  举报