#C11982. Book Shelf Arrangement

    ID: 41358 Type: Default 1000ms 256MiB

Book Shelf Arrangement

Book Shelf Arrangement

Given ( n ) books with specified widths and a shelf with a maximum width ( W ), determine the minimum number of moves required to rearrange the books so that they fit on the shelf. A move is defined as repositioning a book. However, since rearranging does not change the total width of the books, the only possibility for them to fit is if their total width is less than or equal to ( W ). If ( \sum_{i=1}^{n} width_i \leq W ), output 0 (no moves required); otherwise, output -1 (indicating it is impossible).

inputFormat

The input is given via standard input (stdin). The first line contains two integers ( n ) and ( W ) separated by a space. The second line contains ( n ) space-separated integers representing the widths of the books.

outputFormat

Output a single integer: 0 if the books can be arranged such that their total width is less than or equal to ( W ), or -1 if it is impossible.## sample

4 10
1 2 3 4
0