#P1060. [NOIP 2006 普及组] 开心的金明
[NOIP 2006 普及组] 开心的金明
Description
Jinming is very happy today because his family is about to receive the keys to their new home, which has a spacious room just for him. What makes him even happier is that his mom told him yesterday: “You decide which items to buy and how to furnish your room, as long as the total cost does not exceed yuan.” Early this morning, Jinming started making a budget, but there are too many things he wants to buy, so the total will definitely exceed the limit . Therefore, he assigns an importance level to each item, divided into 5 levels, represented by integers 1–5, with level 5 being the most important. He also found the price of each item on the Internet (all in integer yuan). He hopes to maximize the sum of price times importance for the selected items, under the constraint that the total cost does not exceed yuan (it may be equal to yuan).
Let the price of item be and its importance be . If items are selected with indices , then the desired total is:
$$v_{j_1} \times w_{j_1} + v_{j_2} \times w_{j_2} + \cdots + v_{j_k} \times w_{j_k}.$$Please help Jinming design a shopping list that meets the requirements.
Input Format
The first line contains positive integers separated by a space: (), where is the total amount of money and is the number of items.
From line to line , the -th of these lines (corresponding to item ) contains two non-negative integers , where is the price () and is the importance ().
Output Format
Output positive integer: the maximum possible value of the sum of price times importance for the selected items without exceeding the total amount of money (this value is ).
1000 5
800 2
400 5
300 5
400 3
200 2
3900
Hint
NOIP 2006 Junior, Problem 2.
Translated by ChatGPT 5
京公网安备 11011102002149号