#P9974. [USACO23DEC] Candy Cane Feast B
[USACO23DEC] Candy Cane Feast B
Problem Description
Farmer John’s cows have a strong love for sweets, and they especially enjoy eating candy canes. FJ has cows, and each cow has a specific initial height. He wants to feed them candy canes, where each candy cane has its own length ().
FJ plans to feed the cows the candy canes one by one in the order given in the input. Then, the cows will line up in the order given in the input and take turns walking up to the candy cane. Each cow can eat at most the part up to its own height (because it cannot reach any higher). Even if the cows eat away the bottom of the candy cane, the candy cane stays hanging in its original position and will not be lowered to the ground. If the bottom of the candy cane is already higher than a cow’s height, then that cow may eat nothing during its turn. After every cow has taken its turn eating, each cow’s height increases by the number of units of candy cane it ate. Then Farmer John hangs up the next candy cane, and the cows repeat the process (with the first cow again being the first to eat the next candy cane).
Input Format
The first line contains and .
The next line contains the initial heights of the cows, where each height is in the range .
The next line contains the lengths of the candy canes, where each length is in the range .
Output Format
Output lines, the final height of each cow.
Note that because this problem involves large integers, you may need to use a 64-bit integer type (for example, long long in C/C++).
3 2
3 2 5
6 1
7
2
7
Hint
Sample Explanation 1
The first candy cane has length units.
- The first cow eats the first candy cane up to height , leaving the remaining part of the first candy cane at heights .
- The second cow is not tall enough and cannot eat any of the remaining part of the first candy cane.
- The third cow eats an additional units of the first candy cane. The remaining part of the first candy cane at heights is not eaten.
Next, each cow grows by the amount it ate, so the cows’ heights become .
The second candy cane has length unit and is completely eaten by the first cow.
Test Point Properties
- Test points satisfy .
- Test points have no additional constraints.
Translated by ChatGPT 5