#D9310. Chisaki and Picnic
Chisaki and Picnic
Chisaki and Picnic
O: Chisaki and Picnic
Chisaki, a kindergarten student, decided to bring sweets for the excursion.
There are of sweets, and the th sweet is priced at yen and tastes .
Chisaki has friends, and the th friend cries when she has or more of sweets priced at or more.
Chisaki-chan will be happy if her friends cry, so I'd like to bring some sweets so that it doesn't happen.
Help Chisaki-chan to find out how much the total deliciousness of sweets can be.
input
On the first line, the number of sweets and the number of friends are given, separated by blanks.
Of the following lines, are given on the line, separated by blanks.
Of the following lines, are given on the line, separated by blanks.
output
When you choose a candy to bring so that no friend will cry, output the maximum possible value as the total taste.
Constraint
- are integers greater than or equal to and less than or equal to
- are integers greater than or equal to and less than or equal to
- are integers greater than or equal to and less than or equal to
- Satisfy
- are integers greater than or equal to and less than or equal to
- are integers greater than or equal to and less than or equal to
- Satisfy
Input example 1
3 1 10 1 20 2 30 3 20 2
Output example 1
Four
Bringing the sweets will maximize the total deliciousness of the sweets you bring, as long as you don't make your friends cry.
If you bring both the sweets, your friends will cry because you will be "bringing or more of sweets that cost or more".
Input example 2
5 3 10 1 20 4 30 5 40 2 50 3 20 3 30 4 40 2
Output example 2
Ten
By bringing the sweets, you can maximize the total deliciousness of the sweets you bring, under conditions that will not make any friends cry.
Example
Input
3 1 10 1 20 2 30 3 20 2
Output
4
inputFormat
input
On the first line, the number of sweets and the number of friends are given, separated by blanks.
Of the following lines, are given on the line, separated by blanks.
Of the following lines, are given on the line, separated by blanks.
outputFormat
output
When you choose a candy to bring so that no friend will cry, output the maximum possible value as the total taste.
Constraint
- are integers greater than or equal to and less than or equal to
- are integers greater than or equal to and less than or equal to
- are integers greater than or equal to and less than or equal to
- Satisfy
- are integers greater than or equal to and less than or equal to
- are integers greater than or equal to and less than or equal to
- Satisfy
Input example 1
3 1 10 1 20 2 30 3 20 2
Output example 1
Four
Bringing the sweets will maximize the total deliciousness of the sweets you bring, as long as you don't make your friends cry.
If you bring both the sweets, your friends will cry because you will be "bringing or more of sweets that cost or more".
Input example 2
5 3 10 1 20 4 30 5 40 2 50 3 20 3 30 4 40 2
Output example 2
Ten
By bringing the sweets, you can maximize the total deliciousness of the sweets you bring, under conditions that will not make any friends cry.
Example
Input
3 1 10 1 20 2 30 3 20 2
Output
4
样例
3 1
10 1
20 2
30 3
20 2
4