1817.April Fools' Problem (medium)

Time Limit: 1s Memory Limit: 256MB

The marmots need to prepare k problems for HC2 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 ai CHF, and the printing of a problem on day i (also at most one per day) costs bi 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 Format(From the terminal/stdin)

Input The first line of input contains two space-separated integers n and k (1 \le k \le n \le 2200). The second line contains n space-separated integers a1,...,an (1817_1.png) - the preparation costs. The third line contains n space-separated integers b1,...,bn (1817_2.png) - the printing costs.

Output Format(To the terminal/stdout)

Output Output the minimum cost of preparation and printing k problems - that is, the minimum possible sum ai1+ai2+...+aik+bj1+bj2+...+bjk, where 1 \le i1 \lt i2 \lt ... \lt ik \le n, 1 \le j1 \lt j2 \lt ... \lt jk \le n and i1 \le j1, i2 \le j2, ..., ik \le jk.

Sample Input

Copy
8 4
3 8 7 9 9 4 6 8
2 5 9 4 3 8 9 1
 · \n
 · · · · · · · \n
 · · · · · · · \n

Sample Output

Copy
32
  \n

Hints

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.

Submit

请先 登录

© 2025 FAQs