#K66587. Warehouse Maximum Value
Warehouse Maximum Value
Warehouse Maximum Value
You are given a warehouse with a limited capacity W and n types of products. Each product type is described by two numbers: its value and its weight. You are allowed to take fractional amounts of any product. Your task is to maximize the total value of products that can be stored in the warehouse without exceeding its capacity.
The optimal solution is obtained by taking products in the order of their value-to-weight ratio (i.e. \( \frac{value}{weight} \)) from highest to lowest, including a fractional amount of a product if the remaining capacity is not enough to take it entirely.
Note: The answer is guaranteed to be an integer for the given test cases.
inputFormat
The first line contains two integers n and W (the number of product types and the warehouse capacity, respectively). Each of the next n lines contains two integers, representing the value and weight of a product type.
Input is read from standard input.
outputFormat
Output a single integer --- the maximum total value of products that can be stored in the warehouse, printed to standard output.
## sample3 50
60 10
100 20
120 30
240
</p>