CF1826E.Walk the Runway

提高+/省选-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

A fashion tour consists of mm identical runway shows in different cities. There are nn models willing to participate in the tour, numbered from 11 to nn. People in different cities have different views on the fashion industry, so they rate each model differently. In particular, people in city ii rate model jj with rating ri,jr_{i, j}.

You are to choose some number of kk models, and their order, let the chosen models have indices j1,j2,…,jkj_1, j_2, \dots, j_k in the chosen order. In each city, these kk models will walk the runway one after another in this order. To make the show exciting, in each city, the ratings of models should be strictly increasing in the order of their performance. More formally, for any city ii and index tt (2≤t≤k2 \leq t \leq k), the ratings must satisfy ri,jt−1<ri,jtr_{i,j_{t - 1}} \lt r_{i,j_t}.

After all, the fashion industry is all about money, so choosing model jj to participate in the tour profits you pjp_j money. Compute the maximum total profit you can make by choosing the models and their order while satisfying all the requirements.

一场时装巡演包含在 mm 个不同城市举行的 mm 场完全相同的时装秀。共有 nn 位模特愿意参加此次巡演,编号为 11 至 nn。不同城市的观众对时尚产业的看法各异,因此他们对每位模特的评分也不同。具体而言,第 ii 个城市对第 jj 位模特的评分为 ri,jr_{i, j}。

你需要从中选出 kk 位模特(kk 可为任意非负整数),并确定其出场顺序;设所选模特按出场顺序的编号依次为 j1,j2,…,jkj_1, j_2, \dots, j_k。在每个城市中,这 kk 位模特将严格按此顺序依次走上T台。为使时装秀富有观赏性,要求在每个城市中,模特们的评分必须严格递增。更准确地说,对任意城市 ii 和任意索引 tt(其中 2≤t≤k2 \leq t \leq k),评分需满足 ri,jt−1<ri,jtr_{i,j_{t - 1}} \lt r_{i,j_t}。

最终,时尚产业归根结底关乎收益:选择第 jj 位模特参与巡演可为你带来 pjp_j 的利润。请计算在满足上述所有约束条件下,你能获得的最大总利润。

输入格式

The first line contains two integers mm and nn (1≤m≤5001 \leq m \leq 500, 1≤n≤50001 \leq n \leq 5000) — the number of shows and the number of models willing to participate respectively.

The second line contains nn integers pjp_j (1≤pj≤1091 \leq p_j \leq 10^9) — the profit you get inviting the jj-th model to the tour.

The next mm lines each contain nn integers. Line number ii contains nn integers ri,jr_{i, j} (1≤ri,j≤n1 \leq r_{i, j} \leq n) — the ratings of models in city ii.

第一行包含两个整数 mm 和 nn(1≤m≤5001 \leq m \leq 500,1≤n≤50001 \leq n \leq 5000)—— 分别表示时装秀的数量和愿意参加的模特数量。

第二行包含 nn 个整数 pjp_j(1≤pj≤1091 \leq p_j \leq 10^9)—— 表示邀请第 jj 位模特参加巡演所获得的利润。

接下来的 mm 行,每行包含 nn 个整数。第 ii 行包含 nn 个整数 ri,jr_{i, j}(1≤ri,j≤n1 \leq r_{i, j} \leq n)—— 表示第 jj 位模特在第 ii 座城市的评分。

输出格式

Output a single integer — the largest total amount of money you can get.

输出一个整数——你能获得的最大总金额。

输入输出样例

  • 输入#1

    3 5
    10 10 10 10 10
    1 2 3 4 5
    1 5 2 3 4
    2 3 4 5 1

    输出#1

    30
  • 输入#2

    3 5
    10 10 10 10 50
    1 2 3 4 5
    1 5 2 3 4
    2 3 4 5 1

    输出#2

    50
  • 输入#3

    1 1
    1000000000
    1

    输出#3

    1000000000
  • 输入#4

    5 5
    1000000000 1000000000 1000000000 1000000000 1000000000
    5 4 3 2 1
    5 4 3 2 1
    5 4 3 2 1
    5 4 3 2 1
    5 4 3 2 1

    输出#4

    5000000000
  • 输入#5

    1 3
    1 2 3
    3 3 3

    输出#5

    3

说明/提示

In the first example, there are 33 invited models. The show consists of models in the order [1,3,4][1, 3, 4].

Then, the corresponding ratings in the cities are as follows:

  • City 11 — [1,3,4][ 1, 3, 4 ].
  • City 22 — [1,2,3][ 1, 2, 3 ].
  • City 33 — [2,4,5][ 2, 4, 5 ].

You can see that the ratings are increasing. So the total profit is 10+10+10=3010 + 10 + 10 = 30. It can be proven that we can't achieve a bigger profit.

In the second example, we can invite the fifth model to the tour, which would result in a total profit of 5050. It can be proven that we can't achieve a bigger profit.

In the third example, we invite the single model to the tour, which results in a total profit of 1 000 000 0001\,000\,000\,000.

In the fourth test case, we can invite all the models and make the show in the order [5,4,3,2,1][ 5, 4, 3, 2, 1 ]. The total profit is 5⋅1 000 000 000=5 000 000 0005 \cdot 1\,000\,000\,000 = 5\,000\,000\,000.

在第一个例子中,共有 33 位受邀模特。时装秀的模特出场顺序为 [1,3,4][1, 3, 4]。

此时,各城市对应的评分如下:

  • 城市 11 — [1,3,4][ 1, 3, 4 ]。
  • 城市 22 — [1,2,3][ 1, 2, 3 ]。
  • 城市 33 — [2,4,5][ 2, 4, 5 ]。

可以看出,各城市的评分均为递增序列。因此总收益为 10+10+10=3010 + 10 + 10 = 30。可以证明,无法获得更高的收益。

在第二个例子中,我们可以邀请第五位模特参加巡演,从而获得总收益 5050。可以证明,无法获得更高的收益。

在第三个例子中,我们仅邀请一位模特参加巡演,从而获得总收益 1 000 000 0001\,000\,000\,000。

在第四个测试用例中,我们可以邀请所有模特,并按顺序 [5,4,3,2,1][ 5, 4, 3, 2, 1 ] 进行时装秀。总收益为 5⋅1 000 000 000=5 000 000 0005 \cdot 1\,000\,000\,000 = 5\,000\,000\,000。

输入解题思路,AI测评打分。不知道怎么写?

首页