#P4713. 「语文」凑字数

    ID: 3410 远端评测题 2000ms 512MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>贪心O2优化枚举,暴力洛谷月赛

「语文」凑字数

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 LL characters per line, and the minimum word count requirement is measured by the number of lines.

That is, as long as he reaches MM 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 NN sentences, and each sentence has its own length aia_i—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., 2020 points). The minimum for each part is 00 points, meaning that even if a part would go below 00, it is counted as 00. Here, our rubric has KK parts, each with a full score of SS. Depending on the aspect, Xiao F uses a KK-tuple si=(si,1,si,2,,si,K)s_i = (s_{i,1}, s_{i, 2}, \cdots, s_{i, K}) to describe the relation between sentence ii and sentence i+1i + 1, where each number is an integer. The jj-th number si,js_{i, j} means:

  • If it is positive, then splitting sentences ii and i+1i + 1 will deduct si,js_{i, j} points from part jj.
  • If it is negative, then not splitting these two sentences will deduct si,j-s_{i, j} points from part jj.
  • If it is 00, then whether to split has no effect on the score for that part.

Starting from full marks for each part (i.e., SS per part), after applying the above deductions, each part is floored at 00, 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 CC points from the word-count score, and the overall total is floored at 00.

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 66 integers: N,M,L,K,S,CN, M, L, K, S, C, as described above.
  • The second line contains NN integers, where the ii-th is aia_i, the length of sentence ii.
  • The next N1N - 1 lines each contain KK integers; on the ii-th of these lines, the jj-th integer is si,js_{i, j}.

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 10+95=1410 + 9 - 5 = 14 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 8+100=188 + 10 - 0 = 18 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 1(21pts)1(21 \mathrm{pts}): N10N \leq 10.

Subtask 2(21pts)2(21 \mathrm{pts}): K=1K = 1.

Subtask 3(31pts)3(31 \mathrm{pts}): N×ai800N \times a_i \leq 800.

Subtask 4(77pts)4(77 \mathrm{pts}):

  • 1N,M,ai2001 \leq N, M, a_i \leq 200.
  • 3L2003 \leq L \leq 200.
  • 1K51 \leq K \leq 5.
  • 0S,C,si,j2000 \leq S, C, |s_{i, j}| \leq 200.

Translated by ChatGPT 5