There are a group of people standing in line for a taco stand. This taco stand is special in that it's slogan is "The older you are, the more you get!". To make sure though that there isn't any funny business, the owner of the stand has set up a few rules:
- Everyone standing in line will get at least 1 taco
- Each person can only see (compare) themselves to the person in front and behind them
- The owner wants to hand out as few tacos as possible
How does the taco stand owner decide how many tacos to give to each one such that all 3 rules apply.
Examples:
For the following ages of the people in the line: 10, 20, 25, 36. The owner can hand out the following amount of tacos: 1, 2, 3, 4
For the following ages: 10, 19, 25, 20. He can hand out: 1, 2, 3, 1
Explanation: Since the last person in the line cannot see past the person in front of him, we can safely give him 1 taco and all rules apply.
Notes & Clarification: The taco owner can see the whole line and knows their ages. The people have lined up randomly and cannot be moved. There could be neighbours with the same age. Furthermore, Rule 2 means that, indeed, the taco owner is not as generous as one might think. If we focus on one person, then the following has to hold:
- If I am older than the person in front of me, I will get more tacos than him
- If I am older than the person behind me, I will get more tacos than him
- If I am younger than the person in front of me, he will get more tacos than me
- If I am younger than the person behind me, he will get more tacos than me
So the slogan is "localized" in a sense