PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#GD0000176. Các nhiệm vụ (Quests)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

2 lộ trình

Các nhiệm vụ (Quests)

Quests

Source: Codeforces

Version: Phuoc Hung OJ Extended

Problem Statement

Monocarp plays a game with nn quests, numbered 1,2,…,n1,2,\ldots,n. Initially only quest 11 is available. Quest ii becomes available after every quest with an index smaller than ii has been completed at least once.

A quest may be completed repeatedly. The first completion of quest ii awards aia_i experience points; each subsequent completion of the same quest awards bib_i points.

Monocarp has time for at most kk quest completions, including repetitions. Find the maximum total experience he can earn.

Input

Line 1 contains integers n,kn,k: the number of quests and the maximum number of completions.

Line 2 contains nn integers a1,…,ana_1,\ldots,a_n: first-completion rewards.

Line 3 contains nn integers b1,…,bnb_1,\ldots,b_n: repeat-completion rewards.

Output

Print one integer: the maximum total experience obtainable in at most kk completions.

Subtasks

  • Subtask 1 (20 points): 1≤n,k≤81\le n,k\le8; 1≤ai,bi≤1031\le a_i,b_i\le10^3 for every 1≤i≤n1\le i\le n.
  • Subtask 2 (30 points): 1≤n,k≤20001\le n,k\le2000; 1≤ai,bi≤1031\le a_i,b_i\le10^3 for every 1≤i≤n1\le i\le n.
  • Subtask 3 (50 points): 1≤n,k≤2⋅1051\le n,k\le2\cdot10^5; 1≤ai,bi≤1031\le a_i,b_i\le10^3 for every 1≤i≤n1\le i\le n.

Examples

Input

4 7
4 3 1 2
1 1 1 1

Output

13

Explanation

There are 44 quests and at most 77 completions. Completing quests 1,2,3,41,2,3,4 for the first time gives 4+3+1+2=104+3+1+2=10 points. The remaining three completions can repeat an unlocked quest, adding 1+1+1=31+1+1=3, for a total of 1313. Unlocking only two or three quests yields at most 1212, so 1313 is optimal.