跳到主要内容
图灵 OJTURING / ONLINE JUDGE

#F0777. April Fools' Problem (medium)

    ID: 783 传统题 2000ms 256MiB 尝试: 0 已通过: 0 难度: (无) 上传者: 标签>待分类整理状态难度待定难度共享题库Codeforces英文题面题目来源题面语言

April Fools' Problem (medium)

题目描述

N. April Fools' Problem (medium)
time limit per test
4 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

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

The first line of input contains two space-separated integers n and k (1≤kn≤2200). The second line contains n space-separated integers a1,...,an () − the preparation costs. The third line contains n space-separated integers b1,...,bn () − the printing costs.

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≤i1<i2<...<ikn, 1≤j1<j2<...<jkn and i1j1, i2j2, ..., ikjk.

Example
Input
8 4
3 8 7 9 9 4 6 8
2 5 9 4 3 8 9 1
Output
32
Note

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.


题目来源:fps-www.educg.net-codeforce-1-2833.xml.zip;FPS 共享题包,题包内第 204 题。保留原作者与原赛事署名。