#t393. 开心的金明(happy)
开心的金明(happy)
Happy Jinming
Problem Background
Special for beginners, ^_^
Problem Description
Jinming is very happy today: his family's newly bought house is about to get its keys, and the new house has a large room that is exclusively his. What makes him even happier is that yesterday his mother said to him: "For the items your room needs and how to arrange them, you decide — as long as it doesn't exceed yuan." Early this morning Jinming started budgeting, but he wants to buy too many things and will surely exceed the yuan limit set by his mother. So he assigns an importance to each item, in 5 levels represented by integers 1~5, where level 5 is the most important. He also looked up each item's price online (all integer yuan). He wants, without exceeding yuan (it may equal yuan), to maximize the sum of the product of each item's price and its importance.
Let the -th item have price and importance . If items are selected, numbered in order, then the desired total is:
. (where * means multiplication)
Please help Jinming design a shopping list that satisfies the requirement.
Input Format
The first line contains two positive integers separated by a space:
(where is the total budget, and is the number of items to buy.)
From the 2nd line to the -th line, the -th line gives the basic data of item numbered , with non-negative integers per line:
(where is the item's price (), and is its importance ().)
Output Format
Output a single positive integer — the maximum possible sum of (price × importance) for items whose total price does not exceed the budget ().
Sample Input
1000 5
800 2
400 5
300 5
400 3
200 2
Sample Output
3900
Constraints
1 second, 1024 KiB for each test case.