#B4093. Minimum Parcel Packing
Minimum Parcel Packing
Minimum Parcel Packing
Little Hua has n different books (numbered from 1 to n) with weights \(a_1,a_2,\dots,a_n\) in kilograms. He wants to send these books to his friend using a courier service, but each parcel can hold at most \(m\) kilograms (the weight can be exactly \(m\)). Moreover, when packing a parcel, he will list the books inside by their numbers. Your task is to determine a way to pack all the books into parcels such that the total number of parcels is minimized. If there are multiple valid solutions, any one of them will be accepted.
Input Format
The first line contains two integers \(n\) and \(m\), where \(n\) is the number of books and \(m\) is the maximum weight capacity of each parcel.
The second line contains \(n\) integers \(a_1,a_2,\dots,a_n\) representing the weights of the books.
Output Format
Output the minimum number of parcels needed on the first line. Then, output exactly that many lines, each representing one parcel. In each of these lines, list the book numbers (in increasing order) that are assigned to that parcel, separated by spaces.
Note: It is guaranteed that each book can be individually sent (i.e. \(a_i \leq m\)).
inputFormat
The first line contains two integers \(n\) and \(m\) which denote the number of books and maximum weight per parcel respectively. The second line contains \(n\) integers: \(a_1,a_2,\dots,a_n\), where \(a_i\) is the weight of the \(i\)-th book.
outputFormat
On the first line, print the minimum number of parcels required. Each of the following lines should contain the book numbers (1-indexed) in one parcel, listed in increasing order. If there are multiple valid packings with the minimum number of parcels, output any one of them.
sample
4 5
2 3 4 1
2
1 2
3 4
</p>