#C5676. Minimum Robots Required for Package Delivery

    ID: 49351 Type: Default 1000ms 256MiB

Minimum Robots Required for Package Delivery

Minimum Robots Required for Package Delivery

You are given n packages with individual weights and a fleet of robots, each of which can carry a total weight of at most W. Your task is to determine the minimum number of robots required to deliver all packages if each robot can carry one or more packages as long as the sum of their weights does not exceed W.

If any package weighs more than W (i.e. \(w_i > W\)), then it is impossible to deliver all packages and you should output \(-1\).

The packages can be rearranged in any order for optimal packing. Use a greedy strategy by sorting the packages in non‐increasing order and iteratively assigning them to each robot until no more packages can fit.

inputFormat

The input is given via standard input (stdin) in the following format:

n W
w1 w2 ... wn

Here, the first line contains two integers: n (the number of packages) and W (the maximum weight capacity of each robot). The second line contains n space-separated integers representing the weights of the packages.

outputFormat

Output a single integer to standard output (stdout) representing the minimum number of robots required. If it is impossible to deliver all packages, output -1.

## sample
5 15
5 10 15 5 5
3

</p>