Two points A and B are 1000 Km apart,We are tasked with transporting 3000 apples from point A to B in a truck.Truck's maximum load is 1000 apples.There's also a tax we pay each time we cover 1 Km heading towards B(1 apple).How many apples get delivered.Ans is 833 but don't quite see how they get to that? Any help will be appreciated.
=== new answer ===
The guy has 3000 apples so he knows he will need to make three trips. So he knows we will have to pay taxes for each kilometer 3 times. So he says to himself: "As a drive along I'm going to set aside apples for my next two trips just to plan ahead."
So at each km. He pays an apple in tax and he sets aside two apples at the side of the road for his next two trips. He does that for 332 km and he is left with 4 apples. He goes one more km, pays the taxes an has three apples left. He thinks: " No point in leaving both. Then I'll have one left that I'll have to spend in tax for no purpose as it won't get any apples through. I'll leave just one here at the 333 km. mark." He does. He goes to the 334 km mark with his two apples and pays one in tax and leaves one.
So now he has an empty truck. There are two apples at each of the markers 1-332. And one apple at markers 333, and 334.
He goes back to the beginning. He loads his truck. He goes to each marker picks up one of the apples he had set aside and pays the tax with it and that way keeps his truck fully loaded and leaves one apple for his final trip. He does this for the first 332 marks.
At 333, and 334 he pays from the truck. There are on apple at markers 1-334. And you has a truck with 998 apples.
At the next 449, 335- 833 markers he pays one apple in tax and sets aside one apple for his final trip. At the 833 marker the situation is this: 1000 apples at the starting point; one apple at each of the post markers, and an empty truck.
He goes back. Loads his truck. At each marker he picks up an apple and pays the tax with it and keeps his truck fully loaded. He now has a full truck and 167 marker left to go. He pays from his truck and ends up delivering 833 apples.
Notice this is exactly as if he had three trucks traveling at the same time. At 334. The three drivers would say "Hey! Let's combine loads so that only two of us have to go on". Or if at each post the third driver said: "Hey, the tolls on me; you two keep you trucks loaded."
==== old answer ====
I'm assuming the tax is one apple per kilometer. Thus if you start with 1000 apples to be delivered you will pay 1000 kilometers and up with no apples delivered. But if you start of with 1000 apples and go 999 kilometers, cache your 1 remaining apple. Go back take the next thousand apples and and and cache the one remaining apple, go back and take the last thousand and cache the remaining apple, and then you take the three cached apples and go the last mile and 2 apples will be delivered.
The thing is to minimize the travel you must do. You must make three trips if you have more than two truckloads of apples. But once you travel the first 1000 kilometers, you will only have 2000 apples or to truckloads left. So you only have to make two trips the rest of the way.
Take 1000 apples. Go 333 km and dump the 667 apples. Go back and pick up the next 1000 apples. Go 333 km and dump 333 of the apples making 100 apples at the 333 km marking. Go to 334 km and drop the remaining 333 apples.
You now have 1000 apples at 333 km. You have 333 apples at 334. And 1000 apples at 0. And you have driven 667 km. In one direction.
You go get the remaining apples and go to the 334 drop of 666 apples. You have 1000 apples at 333 and 999 at 334.
Go back to 333. Load your truck. Drive 500 kilometers to 833 and drop of 500 apples. Go back to 334 and pick up 999 apple. Drive 499 kilometers to 833 and drop 500 apples. You now have 1000 apples at 833. Load up. Drive and pay 137 apples for the remaining 137 km. You end up delivering 833 apples.
That's as efficient as you can get as you had to but only had to cover the same ground three times when you had over two truckloads of apples. Once you were down to two of fewer you had and you only covered the same ground twice. Once you were down to one truckload or less you only covered that ground once.
There are 1334 apples at the 333 km mark. Go back and pick up the remaining 1000 apples. Go 333 km and dump 667 apples. there