#K75682. Bakery Pastry Production Optimization

    ID: 34474 Type: Default 1000ms 256MiB

Bakery Pastry Production Optimization

Bakery Pastry Production Optimization

You run a bakery that produces various types of pastries. Each pastry type has a specific daily demand and the bakery has a fixed daily production limit \(m\). Your task is to determine the maximum number of different pastry types for which the bakery can completely fulfill the demand without exceeding the production limit.

The problem can be described mathematically as follows: Given \(n\) pastry types with demands \(d_1, d_2, \ldots, d_n\) and a production limit \(m\), find the maximum number \(k\) such that there exists a subset of pastry types \(S\) with \(|S| = k\) satisfying:

[ \sum_{d \in S} d \leq m ]

To solve this, a common approach is to sort the demand values in ascending order and then accumulate them until the total exceeds \(m\). The count of accumulated values gives the maximum number of pastry types for which the demand can be met.

inputFormat

The input is read from standard input and consists of two parts:

  • The first line contains two integers \(n\) and \(m\), where \(n\) is the number of pastry types and \(m\) is the daily production limit.
  • If \(n > 0\), the second line contains \(n\) space-separated integers representing the demands for each pastry type. If \(n = 0\), the second line will be empty.

outputFormat

Output a single integer representing the maximum number of pastry types for which the bakery can fully meet the demand without exceeding the production limit.

## sample
5 15
3 6 2 7 5
3