Problem1654--CF802 - N. April Fools' Problem (medium)

1654: CF802 - N. April Fools' Problem (medium)

[Creator : ]
Time Limit : 2.000 sec  Memory Limit : 256 MiB

Description

The marmots need to prepare $k$ problems for HC${^2}$ over $n$ days. Each problem, once prepared, also has to be printed.
The preparation of a problem on day $i$ (at most one per day) costs $a_i$ CHF, and the printing of a problem on day $i$ (also at most one per day) costs $b_i$ CHF. Of course, a problem cannot be printed before it has been prepared (but doing both on the same day is fine).
What is the minimum cost of preparation and printing?

Input

The first line of input contains two space-separated integers $n,k\ (1≤k≤n≤2200)$. 
The second line contains $n$ space-separated integers $a_1,...,a_n\ (1 \leq a_i \leq 10^9)$ − the preparation costs. 
The third line contains $n$ space-separated integers $b_1,...,b_n\ (1 \leq b_i \leq 10^9)$ − the printing costs.

Output

Output the minimum cost of preparation and printing $k$ problems − that is, the minimum possible sum $a_{i_1}+a_{i_2}+...+a_{i_k}+b_{j_1}+b_{j_2}+...+b_{j_k}$, where $1≤i_1<i_2<...<i_k≤n,\ 1≤j_1<j_2<...<j_k≤n$ and $i_1≤j_1,i_2≤j_2, ...,i_k≤j_k$.

Sample 1 Input

8 4
3 8 7 9 9 4 6 8
2 5 9 4 3 8 9 1

Sample 1 Output

32
In the sample testcase, one optimum solution is to prepare the first problem on day 1 and print it on day 1, prepare the second problem on day 2 and print it on day 4, prepare the third problem on day 3 and print it on day 5, and prepare the fourth problem on day 6 and print it on day 8.

HINT

CF802.

Source/Category

最小费用最大流