#K42337. Animal Food Distribution
Animal Food Distribution
Animal Food Distribution
You are given a list of animal species and for each species, a series of food requests along with the total available food portions. For each species, follow the requests in order. If the remaining food is sufficient to satisfy the current request, subtract it from the available food and move on. However, if at any request the available food is less than the requested amount, you should stop processing any further requests for that species.
The task is to compute the remaining food portions for each species after attempting to satisfy the requests in order.
Formally, suppose each species \( s \) has an initial available amount \( A_s \) and a list of requests \( [r_{s,1}, r_{s,2}, \dots, r_{s,k}] \). Then the remaining food \( R_s \) is computed as follows:
[ R_s = A_s - \sum_{i=1}^{j-1} r_{s,i}\quad \text{where} \quad j = \min{i: A_s - \sum_{k=1}^{i-1} r_{s,k} < r_{s,i}} , (\text{if such } i \text{ exists, otherwise } R_s = A_s - \sum_{i=1}^{k} r_{s,i}) ]
If a species has no food requests, its remaining food is the same as the available food.
inputFormat
The first line contains a single integer \( N \) representing the number of animal species. For each species, the input is given in the following format:
- A line containing a string \( S \) denoting the name of the species.
- A line with an integer \( M \) denoting the number of food requests for that species.
- If \( M > 0 \), a line containing \( M \) space-separated positive integers representing the food portions requested.
- A line with a single integer representing the total available food portions for that species.
The species are processed in the order they appear in the input.
outputFormat
For each species, output one line containing the species name and the remaining food portions separated by a single space, in the same order as the input.
## sample3
lion
3
2 3 2
5
tiger
2
1 4
5
bear
3
3 1 1
4
lion 0
tiger 0
bear 0
</p>