#C4499. Maximum Production Lines

    ID: 48043 Type: Default 1000ms 256MiB

Maximum Production Lines

Maximum Production Lines

In this problem, you are given a total budget (B) and (n) available production lines. Each production line is characterized by its cost (x_i) and its production time (y_i). The production time is not used directly in the decision process. Your goal is to select as many production lines as possible such that the total cost does not exceed (B).

A simple greedy strategy is to sort the production lines by their cost (x_i) in ascending order and then choose them one by one until the budget is exceeded. Formally, if the sorted costs are (x_1, x_2, \ldots, x_n), then you need to find the maximum (k) such that: [ \sum_{i=1}^{k} x_i \leq B ]

This problem tests your ability to implement greedy algorithms and handle input/output through standard streams.

inputFormat

The input is read from standard input (stdin). The first line contains two integers (n) and (B) separated by space, where (n) is the number of production lines and (B) is the total budget. The next (n) lines each contain two integers (x_i) and (y_i) representing the cost and production time of the (i)-th production line.

outputFormat

Print a single integer representing the maximum number of production lines that can be built without exceeding the budget (B). The output should be written to standard output (stdout).## sample

5 50
10 5
20 8
30 7
25 6
15 9
3