main litres and the reserve one holds reserve litres. The engine draws fuel only from the main tank, and the truck covers 10 km per litre.
Every time another 5 litres have been burned from the main tank, 1 litre is instantly moved from the reserve tank into the main tank, provided the reserve still has fuel. The transfer happens only at those moments, in whole litres, never gradually.
Return how many kilometres the truck travels before the main tank runs dry.main=12, reserve=1 → 130
After 5 litres, 1 litre moves over from the reserve, leaving 8 in the main tank. After another 5 the reserve is already empty. 13 litres are burned in total, which is 130 km.
main=4, reserve=10 → 40
The main tank never gets to burn 5 litres, so no transfer happens: 40 km.
main=9, reserve=3 → 110
After 5 litres one litre is added (5 left), after the next 5 another one (1 left). 11 litres in total, which is 110 km.
main ≤ 100reserve ≤ 100main=12, reserve=1
130
Run checks the first 3 tests in your browser. Submit checks all 79 tests on the server, hidden ones included.