This is a question nobody was able to answer correctly to at a "flash test" in my class in my college:
We are given:
int N < 1000 slots of time
int[] C: -10 000 <= C[i] <= 10 000 payment corresponding to each of the slots
int T: number of slots we have to use
The problem is stated in the following way:
A lazy worker has N slots of time in a total workday.
For each slot of time he gets a certain payment (C[i] - which, unrealistically, can also be negative).
He wants to choose intervals of exactly T slots so that he will get the biggest payment. We have to choose the intervals he will work in. For example [1, 4] - from the first slot to the 4th.
The problem is that every time he takes a break, when he comes back to work, the first slot he works will not be paid, because he is getting used to work again, just like a lazy person. Therefore, we can also choose empty intervals like [5, 5], this could come in handy if we have negative payments. These will get the payment 0, regardless of what payment is associated to the slot beforehand.
To make it clearer, I'm going to give a simple example:
Let's say we have N=5 slots, and we want to choose T=4. C={3, 9, 1, 1, 7}
The best solution is the intervals [1, 2]; [4, 5] with a total payment of 9+7=16
We cover a total of T=4 slots, the solution is valid.