[ABC373F] 收益递减背包 (Knapsack with Diminishing Values)
[ABC373F] 收益递减背包 (Knapsack with Diminishing Values)
Score : points
Problem Statement
There are types of items. The -th type of item has a weight of and a value of . Each type has items available.
Takahashi is going to choose some items and put them into a bag with capacity . He wants to maximize the value of the selected items while avoiding choosing too many items of the same type. Hence, he defines the happiness of choosing items of type as . He wants to choose items to maximize the total happiness over all types while keeping the total weight at most . Calculate the maximum total happiness he can achieve.
Constraints
-
-
-
-
-
All input values are integers.
Input
The input is given from Standard Input in the following format:
$N$ $W$
$w_1$ $v_1$
$w_2$ $v_2$
$\vdots$
$w_N$ $v_N$
Output
Print the answer.
Sample Input 1
2 10
3 4
3 2
Sample Output 1
5
By choosing items of type and item of type , the total happiness can be , which is optimal.
Here, the happiness for type is , and the happiness for type is .
The total weight is , which is within the capacity .
Sample Input 2
3 6
1 4
2 3
2 7
Sample Output 2
14
Sample Input 3
1 10
1 7
Sample Output 3
12