## Editorial for TLE '16 Contest 6 (Mock CCC) J5 - Meal Plan

Remember to use this editorial

**only**when stuck, and**not to copy-paste code from it**. Please be respectful to the problem author and editorialist.**Submitting an official solution before solving the problem yourself is a bannable offence.**We can make a 2-dimensional integer array . For any and , represents how many different ways the student can spend dollars and have the last meal as ( means breakfast, means lunch, and means dinner).

To start off, we know that the first meal must be breakfast, so we scroll through the breakfast options and add to every .

Scrolling through the array, as we get to , we do steps, one for every meal of the day.

- For each lunch option, we add to , since the student's next meal after breakfast must be lunch;
- Similarly, as we get to , then for each dinner option, we add to , since the student's next meal after breakfast must be dinner;
- Lastly, as we get to , then for each breakfast option, we add to , since after breakfast, the student can then begin considering the next day's breakfast.

In the end, we can find the number of ways to pay the most by taking the highest value of where .

**Time Complexity:**

## Comments