A royal mint runs several production batches side by side, one furnace per batch, and every batch keeps its own separate ledger — nothing raised or spent in one batch ever touches another. Batch i begins with count[i] unstruck coin blanks sitting in its furnace and money[i] gold pieces already in its treasury. Reminting one blank into a finished coin costs upgrade[i] gold. Any blank that is not going to be reminted may instead be melted down and sold as scrap silver for sell[i] gold apiece — the mint master may melt down anywhere from zero up to all of the blanks that are being left unreminted.
For each batch, using only that batch's own treasury plus the scrap gold raised from melting the blanks that are not reminted, determine the maximum number of blanks that can be reminted.
n, the number of mint batches.n integers count[1..n].n integers upgrade[1..n].n integers sell[1..n].n integers money[1..n].Print n integers separated by single spaces on one line: for each batch i, the maximum number of blanks that can be reminted.
Example 1
Input
1 4 3 1 2
Expected
1
Explanation
Batch 1 has 4 blanks, costs 3 gold to remint each, sells spares for 1 gold each, and starts with 2 gold. Reminting x=1 blank costs 3 gold; melting the other 3 blanks raises 3 gold, plus the 2 gold on hand gives 5 gold, which covers it. Reminting x=2 would cost 6 gold, but melting the remaining 2 blanks plus the treasury only raises 2+2=4 gold, which is not enough. So the maximum is 1.
Example 2
Input
2 5 3 2 10 3 1 0 50
Expected
3 3
Explanation
Batch 1: reminting x=3 costs 6 gold; melting the remaining 2 blanks raises exactly 6 gold, so it is affordable, while x=4 would cost 8 gold but melting only 1 remaining blank raises just 3 gold. Batch 2 already has 50 gold on hand, comfortably covering all 3 blanks at 10 gold each (30 gold), so every blank can be reminted.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →