I made a video editorial discussing ABC334F : Christmas Present 2. The video talks about how to use the sliding window technique to optimize DP transitions.
I also created 1D version of the problem, with 3 versions so that you can submit your $$$O(N^3)$$$, $$$O(N^2)$$$ and $$$O(N * Log(N))$$$ solution and verify the correctness. You can access the group using this link https://codeforces.net/group/7Dn3ObOpau In the contests section, you'll see a contest by the name DP + Sliding Window.
The problems are untested, so if you spot any issues, please let me know.