#P8806. [蓝桥杯 2022 国 B] 搬砖
[蓝桥杯 2022 国 B] 搬砖
Problem Description
On this day, Xiaoming is moving bricks.
He has a total of bricks. He finds that the weight of the -th brick is and its value is . He suddenly wants to choose some of these bricks and stack them from bottom to top into a tower. For each brick in the tower, the sum of the weights of all bricks above it must not exceed its own value.
He wants to know what the maximum possible total value of such a tower is (that is, the sum of the values of all bricks in the tower).
Input Format
The input has lines. The first line contains a positive integer , which represents the number of bricks.
The next lines each contain two positive integers , representing the weight and value of each brick.
Output Format
One line, an integer representing the answer.
5
4 4
1 1
5 2
5 5
4 3
10
Hint
Sample Explanation
Choose bricks , , and . Stack them from top to bottom in the order , , . The total value is .
Constraints and Notes
For of the testdata, it is guaranteed that .
For of the testdata, it is guaranteed that ; ; .
Lanqiao Cup 2022 National Contest B Group, Problem J.
Translated by ChatGPT 5