By Daniel L. (8th Grade)
https://usaco.org/index.php?page=viewproblem2&cpid=1163
Since N,M <= 50, we can have a slow solution.
You go through all of the N different colors and see if it’s possible. Color i has to appear in a continuous interval. Then for every other color j, then it can be 4 types. 1. It’s to the left of color i 2. It’s in the middle of color i 3. It’s around color i 4. It’s to the right of color i. If it doesn’t satisfy any of these types, then it’s impossible. It’s pretty straightforward, but there are some edge cases to consider.



