CF1859E.Maximum Monogonosity
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You are given an array a of length n and an array b of length n . The cost of a segment [l,r] , 1≤l≤r≤n , is defined as ∣bl−ar∣+∣br−al∣ .
Recall that two segments [l1,r1] , 1≤l1≤r1≤n , and [l2,r2] , 1≤l2≤r2≤n , are non-intersecting if one of the following conditions is satisfied: r1<l2 or r2<l1 .
The length of a segment [l,r] , 1≤l≤r≤n , is defined as r−l+1 .
Find the maximum possible sum of costs of non-intersecting segments [lj,rj] , 1≤lj≤rj≤n , whose total length is equal to k .
输入格式
Each test consists of multiple test cases. The first line contains a single integer t (1≤t≤1000) — the number of sets of input data. The description of the test cases follows.
The first line of each test case contains two integers n and k ( 1≤k≤n≤3000 ) — the length of array a and the total length of segments.
The second line of each test case contains n integers a1,a2,…,an ( −109≤ai≤109 ) — the elements of array a .
The third line of each test case contains n integers b1,b2,…,bn ( −109≤bi≤109 ) — the elements of array b .
It is guaranteed that the sum of n over all test case does not exceed 3000 .
输出格式
For each test case, output a single number — the maximum possible sum of costs of such segments.
输入输出样例
输入#1
5 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 7 2 1 3 7 6 4 7 2 1 5 3 2 7 4 5 4 2 17 3 5 8 16 2 5 9
输出#1
0 10 0 16 28
说明/提示
In the first test case, the cost of any segment is 0 , so the total cost is 0 .
In the second test case, we can take the segment [1,1] with a cost of 8 and the segment [3,3] with a cost of 2 to get a total sum of 10 . It can be shown that this is the optimal solution.
In the third test case, we are only interested in segments of length 1 , and the cost of any such segment is 0 .
In the fourth test case, it can be shown that the optimal sum is 16 . For example, we can take the segments [3,3] and [4,4] .