402223: GYM100703 F Game of words

Memory Limit:256 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

F. Game of wordstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard output

— But how can all of them be acquainted, if no one wants to see anyone else? — Princess still did not find Dragon's plan feasible.

— Not quite, — Dragon circumstantiated, — No one wants an unplanned contact. But, for example, they all come to intellectual competitions eagerly. There are games where teams consist of two people...

Dragon told Princess that qualification competition for Word Game begins in Castles Valley soon. Teams scored enough points participate in the next round of the competition. If several teams score an equal number of points, the team spent less time is placed higher.

Let us describe the rules of qualification game.

Game master has m cards in a pack. Only one word is written on each card. Players take turns. Before the game they agree which of them makes the first move and inform game master about it. Let us call the player who moves first The First Player, and call The Second Player another.

At the beginning, game master gives The First Player a card. The First Player tries to explain the word on the card without naming the word to The Second Player. When the explanation finished, The Second Player says his guess. If The Second Player's answer is the same as the word on the card, the team scores a point. Then, the game master gives The Second Player a card, and The Second Player tries to explain the word on the card to The First Player. Then a card is given to The First Player again... The game continues until cards run out.

But there is an important additional rule in this season. Player must use a terminology of only one subject area when he explains his word. Moreover, a terminology of each subject area should be used only once in qualification game. The n (n ≥ m) subject areas are specified in the rules.

A pair of players — X and Y — has prepared for a qualification game carefully. They believe that each of them can guess any word regardless of a terminology used for explanations. It is simply a matter of time.

After a series of trainings, they studied the time needed to guess the word that was explained with each terminology to each of them.

Now they want to know, what minimum possible time is required for them to score m points. Your tasks is to compute the time.

Input

The first line contains integers m and n (1 ≤ m ≤ n ≤ 400) — the number of cards in a pack and the number of subject areas, which terminologies can be used for explanations.

The second line contains n integers p1, p2, ..., pn, where pj (1 ≤ pj ≤ 106) — the time player X needs to guess a word, if he listens to explanation of this word with jth subject area terminology.

The third line contains n integers q1, q2, ..., qn, where qk (1 ≤ qk ≤ 106) — the time player Y needs to guess a word, if he listens explanation of this word with kth subject area terminology.

Output

Print integer — the minimum possible time, which players need for explanation of m words (in accordance to game rules) in the first line. Players can choose, who of them makes the first step.

ExamplesInput
3 5
5 4 7 6 2
8 3 5 4 2
Output
9
Input
4 4
2 4 6 8
1 4 6 7
Output
18
Note

In the first sample players should play the following way. The first step: player X explains a word to Y using the terms of the 2nd subject area, and Y guesses this word after 3 time units. The second step: player Y uses terms of 5th subject area for explanation of a word, and X guesses this word after 2 time units. The third step: player X explains yet another word using terms of the 4th subject area, and Y guesses this word after 4 time units.

加入题单

上一题 下一题 算法标签: