#P3985. 不开心的金明
不开心的金明
Description
Jinming is very unhappy today. The family is about to get the keys to a second-hand apartment, but there is no spacious room exclusively for him. What makes him even more upset is that his mom told him yesterday: "Which items to buy and how to arrange them is not up to you (there are many restrictions), and moreover the total must not exceed yuan." Early this morning, Jinming started budgeting, but there are so many things he wants to buy that he will surely exceed the yuan limit. So, he assigns to each item an integer importance . He also looked up the price of each item on the Internet (all in integer yuan).
After reviewing the shopping list, his mom requires that the range of the prices of all items on the list (the most expensive minus the cheapest) must not exceed (of course Jinming still does not know why). He hopes, under the constraint that the total cost does not exceed yuan (it can be equal to ), to maximize the total importance .
Please help Jinming design a shopping list that meets the requirements. You only need to tell us the maximum possible sum of importance.
Input Format
The first line contains two positive integers, separated by a space: (where is the total amount of money, and is the number of items he wants to buy).
From line to line , the -th line gives the basic data of the item with ID . Each line contains non-negative integers (where is the price of that item, and is its importance).
Output Format
Output a single positive integer: the maximum possible sum of importance of items whose total cost does not exceed the total amount of money.
5 10
2 800
5 400
5 300
3 400
2 200
1600
Hint
.
.
.
For all , .
.
Translated by ChatGPT 5
京公网安备 11011102002149号