#P10978. Fence
Fence
Problem Description
A team of workers () needs to paint a fence consisting of wooden boards, numbered from left to right as to (). Each worker () should sit in front of board . He can only paint one continuous interval (meaning the boards in the interval must be consecutive). This interval must contain board (in particular, the interval may also be empty, i.e., a worker may choose not to work). In addition, the number of boards painted by worker must not exceed , and he earns dollars for each board he paints (). Each board can be painted by at most one worker. All are distinct.
As the team leader, you need to decide the interval each worker should paint and make sure the total income is maximized. The total income is the sum of all workers' individual incomes.
Write a program to determine the maximum possible total income earned by the workers.
Note: you do not have to paint all boards.
Input Format
The first line of input contains two positive integers .
The next lines each contain three positive integers .
Output Format
Output one integer, representing the maximum total income.
8 4
3 2 2
3 2 3
3 3 5
1 1 7
17
Hint
Translated by ChatGPT 5