#K94217. Maximize Storage

    ID: 38593 Type: Default 1000ms 256MiB

Maximize Storage

Maximize Storage

You are given a collection of baked goods. Each baked good has a name and a weight. Your task is to select as many different baked goods as possible to store without exceeding the total weight capacity W.

Formally, given n items where each item i has a weight wi, select a subset such that

iSwiW,\sum_{i \in S} w_i \leq W,

and the number of items in the subset S is maximized.

If multiple selections yield the same maximum count, the strategy of taking items with the smallest weights first will guarantee a valid and optimal solution.

Input/Output Format: The program will read from standard input and output the result to standard output.

inputFormat

The first line contains two integers n and W separated by a space, where n is the number of baked goods and W is the maximum weight capacity of the storage.

The next n lines each contain a string and an integer. The string represents the name of the baked good and the integer represents its weight.

For example:

5 10
cake 3
cookie 2
bread 4
muffin 5
pie 6

outputFormat

The output should consist of two lines. The first line contains a single integer representing the count of selected baked goods. The second line contains the names of the selected baked goods separated by a space, in the order they were chosen.

If no items can be selected, output 0 on the first line and an empty second line.

## sample
5 10
cake 3
cookie 2
bread 4
muffin 5
pie 6
3

cookie cake bread

</p>