Initialize a variable distance to 0 to keep track of the total distance traveled.
Loop while there is fuel in the main tank.
a. If the main tank has 5 or more liters, consume 5 liters and increase the distance by 50 km.
b. If the additional tank has at least 1 liter, transfer 1 liter to the main tank.
c. If the main tank has less than 5 liters, consume the remaining fuel and add the corresponding distance.
d. End the loop when the main tank is empty.