A traveling chef is booked for a D-day pop-up tour across K partner kitchens, numbered 0 through K-1. On each of the D days (numbered 0 through D-1), the chef -- currently working out of some kitchen -- must make exactly one of two choices:
After relocating, the chef starts the next day already at the new kitchen. On day 0 the chef may begin at any kitchen of their choosing, with no cost or bonus for that initial placement. Determine the maximum total points the chef can accumulate over all D days.
A single integer: the maximum total points achievable over the D days.
Example 1
Input
2 2 3 1 2 4 0 5 2 0
Expected
9
Explanation
Day 0: staying at kitchen 0 earns 3, but relocating to kitchen 1 earns the bonus move[0][1] = 5, which is better -- the chef ends day 0 at kitchen 1 with 5 points. Day 1: staying at kitchen 1 earns 4 more (total 9), while relocating back to kitchen 0 would only add move[1][0] = 2 (total 7). Staying is better, so the maximum total is 9.
Example 2
Input
3 3 1 2 3 4 1 1 0 0 5 0 2 3 2 0 4 3 1 0
Expected
11
Explanation
Starting at kitchen 2 for free, day 0 relocates to kitchen 0, earning move[2][0] = 3 (total 3). Day 1 relocates back to kitchen 2, earning move[0][2] = 3 (total 6). Day 2 stays at kitchen 2, earning stay[2][2] = 5 (total 11). No other plan across the three days scores higher, so the maximum is 11.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →