#K10346. Organize Books on Shelves
Organize Books on Shelves
Organize Books on Shelves
Sophie has a collection of books categorized by genres. Each genre is placed on a separate shelf row. Some shelves may be empty. For each genre, you are given the widths of the books, and your task is to calculate the total shelf width required by summing the widths of the books in that genre. However, if a genre is empty (i.e. no books), output two zeros indicating that there are no full rows and no leftover books.
Note: For each non-empty genre, output a single integer (the sum of widths). For an empty genre, output two integers 0 0 (separated by a space) on its own line.
Input/Output through Standard Streams: The input is read from stdin
and the output should be written to stdout
.
inputFormat
The first line contains an integer n
which represents the number of genres. The following n
lines describe each genre:
- Each line starts with an integer
k
which indicates the number of books in that genre. - If
k > 0
, it is followed byk
integers representing the widths of the books in that genre. Ifk = 0
, the genre is empty.
outputFormat
Output exactly n
lines. For each genre:
- If the genre is non-empty, print a single integer representing the total shelf width (i.e. the sum of the book widths).
- If the genre is empty, print two integers
0 0
(separated by a space) on that line.
1
1 4
4