Ctrl K

Truck with a Reserve Tank

Easy
A truck has two fuel tanks: the main one holds 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.
Example 1
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.

Example 2
main=4, reserve=10 → 40

The main tank never gets to burn 5 litres, so no transfer happens: 40 km.

Example 3
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.

Constraints
  • 1 ≤ main ≤ 100
  • 0 ≤ reserve ≤ 100
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsSum of Binary Strings EasyFold the Digits Down to One EasyCounting Off by Threes and Fives EasyAdding Long Numbers in Strings EasyGrowing Handouts Around the Circle Easy
loading Python…
Input
main=12, reserve=1
Expected
130

Run checks the first 3 tests in your browser. Submit checks all 79 tests on the server, hidden ones included.