#K68347. Bookshelf Rearrangement
Bookshelf Rearrangement
Bookshelf Rearrangement
You are given a list of n books and a record of the number of pages read from each book over d days. Each day, the pages read for each book are provided. Your task is to compute the total number of pages read for each book over all days, and then reorder the books in descending order of pages read. In case of a tie, the books should remain in their original order.
The total pages read for a book can be represented using the formula: \( T = \sum_{i=1}^{d} p_i \), where \( p_i \) is the number of pages read on day i.
Finally, print the names of the books in the new order separated by a space.
inputFormat
The input is given in the following format from standard input:
- The first line contains an integer n (the number of books).
- The second line contains n space-separated strings representing the names of the books.
- The third line contains an integer d (the number of days).
- The next d lines each contain n space-separated integers. The j-th integer on the i-th of these lines corresponds to the number of pages read for the j-th book on that day.
outputFormat
Output a single line containing the reordered list of book names, separated by a space.
## sample3
BookA BookB BookC
2
3 2 1
1 3 2
BookB BookA BookC
</p>