#P1529. April Fools' Problem (medium)

April Fools' Problem (medium)

April Fools' Problem (medium)

题面翻译

给定两个长度为 nn 的序列 a1,a2,,ana_1, a_2, \ldots, a_nb1,b2,bnb_1, b_2, \ldots b_n。要求选出 i1,i2,,iki_1, i_2, \ldots, i_kj1,j2,,jkj_1, j_2, \ldots, j_k,满足

  • 1i1<i2<<ik1\leq i_1< i_2<\ldots< i_k1j1<j2<<jk1\leq j_1< j_2<\ldots< j_k

  • ipjpi_p\leq j_p1pk1\leq p \leq k)。

最小化 p=1kaip+bjp\sum_{p=1}^k a_{i_p}+b_{j_p} 的值。

题目描述

The marmots need to prepare k k problems for HC 2 ^{2} over n n days. Each problem, once prepared, also has to be printed.

The preparation of a problem on day i i (at most one per day) costs ai a_{i} CHF, and the printing of a problem on day i i (also at most one per day) costs bi 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?

输入格式

The first line of input contains two space-separated integers n n and k k ( 1<=k<=n<=2200 1<=k<=n<=2200 ). The second line contains n n space-separated integers a1,...,an a_{1},...,a_{n} () — the preparation costs. The third line contains n n space-separated integers b1,...,bn b_{1},...,b_{n} () — the printing costs.

输出格式

Output the minimum cost of preparation and printing k k problems — that is, the minimum possible sum $ a_{i1}+a_{i2}+...+a_{ik}+b_{j1}+b_{j2}+...+b_{jk} $ , where 1<=i_{1}&lt;i_{2}&lt;...&lt;i_{k}<=n , 1<=j_{1}&lt;j_{2}&lt;...&lt;j_{k}<=n and i1<=j1 i_{1}<=j_{1} , i2<=j2 i_{2}<=j_{2} , ..., ik<=jk i_{k}<=j_{k} .

样例 #1

样例输入 #1

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

样例输出 #1

32

提示

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