#3. 视野一隅
视野一隅
Problem Statement
Little Atom has two sequences, and , each of length . The "value" of an interval is defined as .
Two intervals and are non-overlapping if or .
The length of an interval is defined as .
Given sequences and , Little Atom wants to find several non-overlapping intervals, with a total length of , such that the sum of their values is maximized.
Input Format
The first line contains the total number of test cases .
For each test case, there are 3 lines:
- The first line contains two integers and .
- The second line contains the sequence .
- The third line contains the sequence .
Output Format
For each test case, output the maximum possible sum of the values as described.
Sample Input #1
3
4 4
1 1 1 1
1 1 1 1
3 2
1 3 2
5 2 3
5 1
1 2 3 4 5
1 2 3 4 5
Sample Output #1
0
5
0
Hints
- ,
There is an solution, and you may want to challenge yourself if time permits qwq.
相关
在下列比赛中: