Subsequence Update

시간 제한1.5초메모리 제한2048 MB

요약
주어진 구간에 대해 부분수열을 한 번 뒤집은 뒤, 그 구간의 합이 가질 수 있는 최솟값을 구한다.
난이도

보통10점 중 6점

유형
그리디, 정렬, 누적 합
정답자
아직 제출이 없습니다

문제

After Little John borrowed expansion screws from auntie a few hundred times, eventually she decided to come and take back the unused ones.

But as they are a crucial part of home design, Little John decides to hide some in the most unreachable places --- under the eco-friendly wood veneers.

You are given an integer sequence a_1,a_2,…,a_na\_1, a\_2, \ldots, a\_n, and a segment \[l,r]\[l,r] (1≤l≤r≤n1 \le l \le r \le n).

You must perform the following operation on the sequence exactly once.

  • Choose any subsequence1 of the sequence aa, and reverse it. Note that the subsequence does not have to be contiguous.

Formally, choose any number of indices i_1,i_2,…,i_ki\_1,i\_2,\ldots,i\_k such that 1≤i_1<i_2<…<i_k≤n1 \le i\_1 < i\_2 < \ldots < i\_k \le n. Then, change the i_xi\_x-th element to the original value of the i_k−x+1i\_{k-x+1}-th element simultaneously for all 1≤x≤k1 \le x \le k.

Find the minimum value of a_l+a_l+1+…+a_r−1+a_ra\_l+a\_{l+1}+\ldots+a\_{r-1}+a\_r after performing the operation.


1A sequence bb is a subsequence of a sequence aa if bb can be obtained from aa by the deletion of several (possibly, zero or all) element from arbitrary positions.

입력

Each test contains multiple test cases. The first line contains the number of test cases tt (1≤t≤1041 \le t \le 10^4). The description of the test cases follows.

The first line of each test case contains three integers nn, ll, rr (1≤l≤r≤n≤1051 \le l \le r \le n \le 10^5) --- the length of aa, and the segment \[l,r]\[l,r].

The second line of each test case contains nn integers a_1,a_2,…,a_na\_1,a\_2,\ldots,a\_n (1≤a_i≤1091 \le a\_{i} \le 10^9).

It is guaranteed that the sum of nn over all test cases does not exceed 10510^5.

출력

For each test case, output the minimum value of a_l+a_l+1+…+a_r−1+a_ra\_l+a\_{l+1}+\ldots+a\_{r-1}+a\_r on a separate line.

힌트

On the second test case, the array is a=\[1,2,3]a=\[1,2,3] and the segment is \[2,3]\[2,3].

After choosing the subsequence a_1,a_3a\_1,a\_3 and reversing it, the sequence becomes \[3,2,1]\[3,2,1]. Then, the sum a_2+a_3a\_2+a\_3 becomes 33. It can be shown that the minimum possible value of the sum is 33.

예제1

  1. 예제 1

    입력
    6
    2 1 1
    2 1
    3 2 3
    1 2 3
    3 1 3
    3 1 2
    4 2 3
    1 2 2 2
    5 2 5
    3 3 2 3 5
    6 1 3
    3 6 6 4 3 2
    
    예상 출력
    1
    3
    6
    3
    11
    8