Total Distance Traveled - Problem
Imagine you're a truck driver on a long cross-country journey with a unique dual-tank fuel system! Your truck has two separate fuel tanks: a main tank that powers the engine, and an additional tank that serves as a backup reservoir.
Here's how this fascinating system works:
- ๐ Your truck gets 10 km per liter of fuel efficiency
- โฝ The engine only runs on fuel from the main tank
- ๐ Every time you consume exactly 5 liters from the main tank, the system automatically transfers 1 liter from the additional tank to the main tank (if available)
- โก The fuel transfer is instantaneous and happens immediately when you hit each 5-liter consumption milestone
Given the initial fuel amounts in both tanks, your goal is to calculate the maximum total distance you can travel before running out of fuel completely.
Example: If you start with 5 liters in the main tank and 10 liters in the additional tank, you'll travel 50 km using the initial 5 liters, then receive 1 liter from the additional tank, allowing you to continue your journey!
Input & Output
example_1.py โ Basic Case
$
Input:
mainTank = 5, additionalTank = 10
โบ
Output:
60
๐ก Note:
We start with 5L in main tank. After consuming all 5L (traveling 50km), we trigger one transfer of 1L from additional tank. This 1L allows us to travel 10 more km, giving us a total of 60km.
example_2.py โ Multiple Transfers
$
Input:
mainTank = 1, additionalTank = 2
โบ
Output:
10
๐ก Note:
We have only 1L in main tank, so we can travel 10km. Since we consumed less than 5L total, no transfer from additional tank occurs. The additional tank fuel remains unused.
example_3.py โ No Additional Fuel
$
Input:
mainTank = 25, additionalTank = 0
โบ
Output:
250
๐ก Note:
With 25L in main tank and 0L in additional tank, we can only use the main tank fuel. 25L ร 10km/L = 250km total distance.
Constraints
- 1 โค mainTank, additionalTank โค 1000
- The truck's fuel efficiency is always 10 km per liter
- Transfer only occurs when exactly 5 liters total have been consumed from the main tank
- Each transfer moves exactly 1 liter from additional to main tank
Visualization
Tap to expand
Understanding the Visualization
1
Journey Begins
Truck starts with fuel in both main and additional tanks
2
Fuel Consumption
Engine consumes fuel from main tank at 10km per liter
3
Transfer Trigger
Every 5 liters consumed triggers automatic 1L transfer
4
Journey Continues
Process repeats until no more fuel can be transferred
5
Journey Ends
Calculate total distance when main tank is finally empty
Key Takeaway
๐ฏ Key Insight: Instead of simulating every liter, we can mathematically calculate the total transfers by recognizing that every 5 liters consumed from the main tank triggers exactly 1 liter transfer from the additional tank!
๐ก
Explanation
AI Ready
๐ก Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code