#K75422. Max Items Stored in Bins

    ID: 34416 Type: Default 1000ms 256MiB

Max Items Stored in Bins

Max Items Stored in Bins

You are given n bins, each with a specified capacity, and m items. Your task is to determine the maximum number of items that can be stored by distributing the items among the bins, ensuring that no bin exceeds its capacity. In other words, you can store at most the total capacity of the bins, but you don't have to store more than the available items.

The answer can be mathematically expressed as:

[ \min\Bigl(m, \sum_{i=1}^{n} c_i\Bigr), ]

where \(c_i\) represents the capacity of the \(i^{th}\) bin.

inputFormat

The first line contains two integers n and m where:

  • n is the number of bins,
  • m is the total number of items available.

The second line contains n space-separated integers representing the capacities of the bins.

outputFormat

Output a single integer, representing the maximum number of items that can be stored in the bins.

## sample
5 10
2 2 2 2 2
10

</p>