#P1130. 红牌
红牌
Description
To obtain long-term residency, temporary residents must apply for a red card. The process consists of steps. Each step is handled by a government staff member who checks whether your submitted materials meet the requirements. To accelerate the process, at each step the government assigns staff members to check materials. Unfortunately, not every staff member is efficient. Nevertheless, to embody the policy of “open government,” the department publicly releases the number of days each staff member takes to handle one application.
To prevent all applicants from flocking to the most efficient staff, these staff members are divided into groups. Each group has exactly one staff member at each step. An applicant may choose any one group and may also switch groups. However, switching is strictly limited: it must occur between two adjacent steps, not during a step that has already started but not yet finished; moreover, you can only switch from your current group to group , and from group you may switch to group . There is no limit on the number of switches.
For example, here are groups, with working days for steps per group:
- Group : ;
- Group : ;
- Group : .
In this example, you can choose group for the entire process, which takes days. Alternatively, you may start with group for step one, then switch to group for step two, to group for step three, and to group for step four, for a total of days. You can see that no choice is more efficient than this.
Your task is to find the minimum number of days needed to complete the application.
Input Format
The first line contains two positive integers and , the number of steps and the number of groups.
Then there are lines, each containing non-negative integers. On the -th of these lines , the -th number denotes the number of days group needs to complete step . All day counts do not exceed .
Output Format
Output a single positive integer, the minimum number of days required to complete all steps.
4 3
2 6 1 8
3 6 2 6
4 2 3 6
12
Hint
Constraints: For of the testdata, .
Translated by ChatGPT 5
京公网安备 11011102002149号