#P9900. Assignment
Assignment
Assignment
Problem Description
You are given two sequences of length and a cost matrix of size . The matrix satisfies for all . You can do the following operation arbitrary number of times:
- Select three integers satisfying and , then assign to for all indices between and , inclusive. The cost of this operation is . For all , find the minimum sum of costs to make has at most positions differing from .
Input
The first line contains a single integer (), denoting the number of test cases. For each test case, the first line contains two integers (, ). The second line contains integers (), denoting the sequence . The third line contains integers (), denoting the sequence . The next lines, each contains integers. The -th integer in the -th line denotes (). It is guaranteed that for all , , .
Output
For each test case, output one line with integers denoting the answer.
Sample Input
1
5 2
1 5 3 2 2
2 4 5 4 2
3 3 3 4 4
2 2 3 4 5
3 4 5 6 7
1 1 1 2 4
4 5 5 5 5
Sample Output
7 3 1
Source
2023“钉耙编程”中国大学生算法设计超级联赛(10)