When a route's allocated Beans exceed its cap, the excess Beans are not properly redistributed.
In ship
function, specifically in the loop that checks for cap exceedance (lines 53-62), the current implementation incorrectly handles the case where a shipment amount exceeds the plan cap:
Looking at line 57, remainingBeansToShip -= shipmentPlans[j].cap;
subtracts the entire cap from the remaining Beans, instead of just the excess amount. As a result, the difference between the allocated amount and the cap (the excess Beans) is not added back to remainingBeansToShip
for redistribution to other routes.
Excess Beans that should be redistributed to other routes are lost, reducing the total amount of Beans distributed. Also, the routes processed later in the loop may receive fewer Beans than they should, as the excess Beans from earlier routes are not available for redistribution. The intention of distribution of Beans across routes is not achieved which affects the shipment process.
Manual code review
By calculating the excess Beans and subtracting only the excess amount from remainingBeansToShip
, the redistribution logic will be corrected.
Modify the cap exceedance check;
The contest is live. Earn rewards by submitting a finding.
This is your time to appeal against judgements on your submissions.
Appeals are being carefully reviewed by our judges.