#P4481. [BJWC2018] 序列合并

[BJWC2018] 序列合并

Description

Scape flipped open the problemset and saw this problem:

There is a sequence AA and L,RL, R. At each step, you may merge KK adjacent elements (with LKRL \le K \le R). The cost is the sum of those KK elements, and the merge produces a new element whose value is that same sum.

Find the minimum cost to merge the entire sequence into one element.

Without thinking, Scape wrote an O(n4)\mathcal{O}(n^4) brute force, which actually timed out (TLE). As the king of XX, Scape naturally will not bother with such a “trash” problem; please solve it.

Input Format

The first line contains an integer TT, the number of test cases.

For each test case, the first line contains three integers n,L,Rn, L, R, denoting the length of sequence AA and the bounds on KK.

The second line contains nn integers, the sequence AA.

Output Format

For each test case, output one integer — the answer. If it is impossible, output 00.

3
3 2 2
1 2 3
3 2 3
1 2 3
4 3 3
1 2 3 4
9
6
0

Hint

Constraints:

  • For 20%20\% of the testdata, n20n \le 20.
  • For 60%60\% of the testdata, n50n \le 50.
  • For 100%100\% of the testdata, 1T101 \le T \le 10, n300n \le 300, Ai100A_i \le 100.

Translated by ChatGPT 5