#P4713. 「语文」凑字数
「语文」凑字数
Description
Time is ticking away second by second, yet Xiao F is still staring at the essay prompt, racking his brain. It looks like he will not finish the essay again.
However, Xiao F has a special trick to pad the word count: keep starting new lines. This is because the essay paper allows characters per line, and the minimum word count requirement is measured by the number of lines.
That is, as long as he reaches lines (excluding the title), the requirement is considered met; “reaches” means that the line contains at least one character. Note that due to formatting requirements, the first line of each paragraph has an indentation of two spaces.
Now, he has planned sentences, and each sentence has its own length —including punctuation. We do not consider cases where, for example, a final period would be beyond the last cell and thus avoid wrapping. The connections between these sentences vary in strength: more strongly related sentences are more suitable to be in the same paragraph, while weakly related ones are more suitable to be split into different paragraphs. However, for padding the word count, Xiao F may insert a paragraph break between any two consecutive sentences.
The association between sentences is represented in a special way. We know that when grading, the score is divided into several main parts; for example, the national paper has “Basic,” “Expression,” and “Development,” each with the same total score (e.g., points). The minimum for each part is points, meaning that even if a part would go below , it is counted as . Here, our rubric has parts, each with a full score of . Depending on the aspect, Xiao F uses a -tuple to describe the relation between sentence and sentence , where each number is an integer. The -th number means:
- If it is positive, then splitting sentences and will deduct points from part .
- If it is negative, then not splitting these two sentences will deduct points from part .
- If it is , then whether to split has no effect on the score for that part.
Starting from full marks for each part (i.e., per part), after applying the above deductions, each part is floored at , and summing over parts yields a preliminary total score. After that, if the number of written lines is below the minimum line count, each missing line deducts points from the word-count score, and the overall total is floored at .
If he can get a high-scoring essay, Xiao F will receive a thumbs-up from the teacher. So, please help Xiao F design a plan to maximize the score.
Input Format
- The first line contains integers: , as described above.
- The second line contains integers, where the -th is , the length of sentence .
- The next lines each contain integers; on the -th of these lines, the -th integer is .
Output Format
Output one non-negative integer on a single line, representing the maximum score you can obtain.
4 4 12 2 10 5
5 5 10 4
2 -1
0 0
1 1
18
2 2 10 1 10 1
1 1
2
9
Hint
Explanation for Sample 1
This is the “no paragraph break” arrangement for Sample 1:

With this arrangement, the score is points.
We notice the word-count penalty is too heavy, so we must avoid it.
The optimal solution is as follows:

With this arrangement, the score is points.
Explanation for Sample 2
Even though inserting a break avoids a one-point word-count penalty, it causes a two-point deduction elsewhere, so it is better not to insert a break.
Subtasks
Subtask : .
Subtask : .
Subtask : .
Subtask :
- .
- .
- .
- .
Translated by ChatGPT 5
京公网安备 11011102002149号