Task
The IKPC is right around the corner.
The kindergarten teacher, Theresa, wants to form some teams for the competition.
There are children in her class, and she wants to form exactly teams.
The children are sitting along a line, numbered from to , according to their position in the line.
Child has a team play factor and a programming skill .
Each team must have at least one member, and no child can be assigned to multiple teams.
Children (for some ) can form a team if for each the following conditions hold:
- , and
- there is no child with index such that .
The strength of a team formed this way is .
Your task is to find the maximum possible sum of team strengths that Theresa can achieve by forming exactly teams!
Input data
The input file consists of:
- a line containing integers , .
- a line containing the integers .
- a line containing the integers .
Output data
The output file must contain a single line consisting of 64-bit integer .
Constraints and clarifications
- .
- for each .
- for each .
- IKPC stands for the International Kindergarten Programming Contest
# | Score | Constraints |
---|---|---|
1 | 0 | Examples. |
2 | 9 | . |
3 | 7 | and . |
4 | 11 | . |
5 | 22 | . |
6 | 51 | No additional limitations. |
Example 1
stdin
4 1
1 2 2 3
10 -10 -2 3
stdout
10
Explanation
In the first sample case forming the team consisting only of the first child is optimal.
Example 2
stdin
5 2
5 2 4 3 2
4 3 3 4 3
stdout
10
Explanation
In the second sample case forming one team consisting of the first child and another team consisting of the second and third children is optimal.