#3. 视野一隅

视野一隅

Problem Statement

Little Atom has two sequences, aa and bb, each of length nn. The "value" of an interval [l,r][l, r] (1lrn)(1 \leq l \leq r \leq n) is defined as bral|b_r - a_l|.

Two intervals [l1,r1][l_1, r_1] (1l1r1n)(1 \leq l_1 \leq r_1 \leq n) and [l2,r2][l_2, r_2] (1l2r2n)(1 \leq l_2 \leq r_2 \leq n) are non-overlapping if r1<l2r_1 < l_2 or r2<l1r_2 < l_1.

The length of an interval [l,r][l, r] (1lrn)(1 \leq l \leq r \leq n) is defined as rl+1r - l + 1.

Given sequences aa and bb, Little Atom wants to find several non-overlapping intervals, with a total length of kk, such that the sum of their values is maximized.

Input Format

The first line contains the total number of test cases tt.

For each test case, there are 3 lines:

  • The first line contains two integers nn and kk.
  • The second line contains the sequence aa.
  • The third line contains the sequence bb.

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

  • 1t,n,k4001 \le t, \sum n, \sum k \le 400, ai,bi108|a_i|, |b_i| \le 10^8

There is an O(n2)O(n^2) solution, and you may want to challenge yourself if time permits qwq.