This is a classic problem about maintaining a monotonic queue. I have been solving POJ problems recently, so I am recording it here.
There are $K$ workers and $N$ boards. Each worker can paint at most $L_i$ consecutive boards, and the interval must include board $S_i$. Painting each board earns $P_i$. Find the maximum total income.
Dynamic programming: $DP[i][j]$ is the maximum income after the first $i$ workers paint $j$ boards. Then
Here, $dp[i-1][k] + peo[i].pay*(j-k)$ means that the first $i-1$ workers paint $k$ boards and worker $i$ paints the next $j-k$.
Observe that $dp[i-1][k] + peo[i].pay*(j-k) = dp[i-1][k] - peo[i].payk + peo[i].payj$. The first part, $dp[i-1][k] - peo[i].pay*k$, can be handled with a monotonic queue.