#P1529. April Fools' Problem (medium)
April Fools' Problem (medium)
April Fools' Problem (medium)
题面翻译
给定两个长度为 的序列 和 。要求选出 和 ,满足
-
,。
-
()。
最小化 的值。
题目描述
The marmots need to prepare problems for HC over days. Each problem, once prepared, also has to be printed.
The preparation of a problem on day (at most one per day) costs CHF, and the printing of a problem on day (also at most one per day) costs 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 and ( ). The second line contains space-separated integers () — the preparation costs. The third line contains space-separated integers () — the printing costs.
输出格式
Output the minimum cost of preparation and printing problems — that is, the minimum possible sum $ a_{i1}+a_{i2}+...+a_{ik}+b_{j1}+b_{j2}+...+b_{jk} $ , where 1<=i_{1}<i_{2}<...<i_{k}<=n , 1<=j_{1}<j_{2}<...<j_{k}<=n and , , ..., .
样例 #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 and print it on day , prepare the second problem on day and print it on day , prepare the third problem on day and print it on day , and prepare the fourth problem on day and print it on day .