Subsequence Update
시간 제한1.5초메모리 제한2048 MB
주어진 구간에 대해 부분수열을 한 번 뒤집은 뒤, 그 구간의 합이 가질 수 있는 최솟값을 구한다.
문제
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 , and a segment ().
You must perform the following operation on the sequence exactly once.
- Choose any subsequence1 of the sequence , and reverse it. Note that the subsequence does not have to be contiguous.
Formally, choose any number of indices such that . Then, change the -th element to the original value of the -th element simultaneously for all .
Find the minimum value of after performing the operation.
1A sequence is a subsequence of a sequence if can be obtained from 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 (). The description of the test cases follows.
The first line of each test case contains three integers , , () --- the length of , and the segment .
The second line of each test case contains integers ().
It is guaranteed that the sum of over all test cases does not exceed .
출력
For each test case, output the minimum value of on a separate line.
힌트
On the second test case, the array is and the segment is .
After choosing the subsequence and reversing it, the sequence becomes . Then, the sum becomes . It can be shown that the minimum possible value of the sum is .