There are many mice in the hall of length n. An array of length n is given where a[i] describes the number of mice between the i-th and i+1-th meter of the hall.
You have k cats. Each cat can guard a connected fragment of the hall. The guarded segments may not intersect. Some segments may be left unguarded.
If a cat guards a segment from the i-th to the j-th meter of the hall, where s = a[i] + a[i+1] + ... + a[j-1] mice reside, it will catch max(s-(j-i-1)^2, 0) mice.
What is the maximal number of mice that can be caught?
I suspect that the algorithm should use dynamic programming, but I have no idea how to solve it.
I don't have any code since I don't have any algorithm yet (I try to create it), but my thoughts so far.
We can't use induction wrt to the number of cats. This could produce false results. For example if there's one segment where one cat can catch 7 mice and two disjoint places where a cat can catch 2 mice, then we'll get nothing from the result for one cat.
So we should solve the problem for a subsegment and calculate the answer from the answer for the subsegment.
But I don't know how to proceed further.