#GD0000176. Các nhiệm vụ (Quests)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Các nhiệm vụ (Quests)
Quests
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
Monocarp plays a game with quests, numbered . Initially only quest is available. Quest becomes available after every quest with an index smaller than has been completed at least once.
A quest may be completed repeatedly. The first completion of quest awards experience points; each subsequent completion of the same quest awards points.
Monocarp has time for at most quest completions, including repetitions. Find the maximum total experience he can earn.
Input
Line 1 contains integers : the number of quests and the maximum number of completions.
Line 2 contains integers : first-completion rewards.
Line 3 contains integers : repeat-completion rewards.
Output
Print one integer: the maximum total experience obtainable in at most completions.
Subtasks
- Subtask 1 (20 points): ; for every .
- Subtask 2 (30 points): ; for every .
- Subtask 3 (50 points): ; for every .
Examples
Input
4 7
4 3 1 2
1 1 1 1
Output
13
Explanation
There are quests and at most completions. Completing quests for the first time gives points. The remaining three completions can repeat an unlocked quest, adding , for a total of . Unlocking only two or three quests yields at most , so is optimal.