Please subscribe to the official Codeforces channel in Telegram via the link: https://t.me/codeforces_official.
×

Virtual contest is a way to take part in past contest, as close as possible to participation on time. It is supported only ACM-ICPC mode for virtual contests.
If you've seen these problems, a virtual contest is not for you - solve these problems in the archive.
If you just want to solve some problem from a contest, a virtual contest is not for you - solve this problem in the archive.
Never use someone else's code, read the tutorials or communicate with other person during a virtual contest.

No tag edit access

N. April Fools' Problem (medium)

time limit per test

4 secondsmemory limit per test

256 megabytesinput

standard inputoutput

standard outputThe 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* and *k* (1 ≤ *k* ≤ *n* ≤ 2200). The second line contains *n* space-separated integers *a*_{1}, ..., *a*_{n} () — the preparation costs. The third line contains *n* space-separated integers *b*_{1}, ..., *b*_{n} () — the printing costs.

Output

Output the minimum cost of preparation and printing *k* 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 *i*_{1} ≤ *j*_{1}, *i*_{2} ≤ *j*_{2}, ..., *i*_{k} ≤ *j*_{k}.

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.

Codeforces (c) Copyright 2010-2018 Mike Mirzayanov

The only programming contests Web 2.0 platform

Server time: Dec/13/2018 19:53:54 (f2).

Desktop version, switch to mobile version.

Supported by

User lists

Name |
---|