Sponsored
Use these hints if you're stuck. Try solving on your own first.
The constraints are small enough for an N^2 solution.
Try using dynamic programming.
Solve with full IDE support and test cases