Can anyone please tell what should be our approach to solve this problem
There are N bags. Each bag contains different number of goods. Goods can be of different weights. The goal is to equalize the weights in the bags subject to constraints explained below. Also, it is guaranteed that the bags can always be equalized with same total weight.
Original number of goods in the bag should be same before and after equalization
Any number of swaps required to do equalization, are permitted
Once the weights are equalized one needs to adhere to output specification to print out the result.
The output specification is as follows
The contents of the Bag that contains the lightest weight should be printed in the first line
The next lightest Bag contents should be printed on the second line
So on and so forth, until all Bags along with their contents are printed
Contents within the Bag must be printed in non-decreasing order
Refer example section for better understanding of constraint and print order
First line contains an integer N denoting number of bags
Next 2N lines, each contain the following
First line contains single integer G denoting the number of goods in a bag.
Second line contains G space separated integer which correspond to weight of goods in that bag.
Identify which bag needs to go on first line and print its contents on first line by adhering to output specification mentioned above
Similarly, identify which bag needs to get print on next N-1 lines and print their contents according to output specification mentioned above
Refer Example section for a better understanding of how to print the output
0 < number of bags <= 20
0 < number of goods in each bag <= 20
0 < weight of any individual goods <= 10 ^ 4
20 7 10
4 6 10