You are given two integer arrays and of length , and an integer .
For each 1 \le i \le n, let
You need to choose a segment [l,r] of length such that
For each position , define d_i as follows:
d_i=l-i if i<l;
d_i=0 if l\le i\le r;
d_i=i-r if i>r.
The cost of the segment [l,r] is
Find the minimum possible cost over all valid segments [l,r].
The first line contains two integers and (4 \le n \le 3000, 2 \le k \le n-2).
The second line contains integers a_1,a_2,\ldots,a_n (-10^9 \le a_i \le 10^9).
The third line contains integers c_1,c_2,\ldots,c_n (-10^9 \le c_i \le 10^9).
Print one integer — the minimum possible cost.
Example 1
In the example:
For l=3 and r=4, we have
The distances from the positions to the segment are
Since b_l=b_3=5, we get
Therefore, the cost of this segment is
Since the cost cannot be negative, the answer is .
Subtask ( points): n \le 30 and k = n - 2.
Subtask ( points): n \le 500.
Subtask ( points): No additional constraints.