#K70127. Minimum Boxes to Pack Items

    ID: 33240 Type: Default 1000ms 256MiB

Minimum Boxes to Pack Items

Minimum Boxes to Pack Items

You are given n boxes and m items. Each box has a maximum capacity given by an array of integers. Your task is to determine the minimum number of boxes required to pack all m items. If it is impossible to pack all items using the available boxes, output -1.

Formally, let the capacities of the boxes be \(c_1, c_2, \ldots, c_n\). You need to find the smallest integer \(k\) such that \[ \sum_{i=1}^{k} c_i \ge m, \] where the boxes are selected in descending order of their capacities. If no such \(k\) exists, output \(-1\).

Input/Output Format: See the input and output descriptions below.

inputFormat

The input is read from stdin and consists of two lines:

  • The first line contains two integers n and m, where n is the number of boxes and m is the number of items.
  • The second line contains n space-separated integers representing the maximum capacities of each box.

outputFormat

Output a single integer to stdout denoting the minimum number of boxes required to pack all items. If it is impossible to pack all items, output -1.

## sample
3 10
7 5 6
2