题库练习 Walk the Runway
← 上一题 下一题 →

A15909 | Walk the Runway

时间限制1s
内存限制256MB
通过 / 提交0/0

题目描述

A fashion tour consists of $m$ identical runway shows in different cities. There are $n$ models willing to participate in the tour, numbered from $1$ to $n$ . People in different cities have different views on the fashion industry, so they rate each model differently. In particular, people in city $i$ rate model $j$ with rating $r_{i, j}$ .

You are to choose some number of $k$ models, and their order, let the chosen models have indices $j_1, j_2, \dots, j_k$ in the chosen order. In each city, these $k$ 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 $i$ and index $t$ ( $2 \leq t \leq k$ ), the ratings must satisfy $r_{i,j_{t - 1}} < r_{i,j_t}$ .

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

输入格式

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

The second line contains $n$ integers $p_j$ ( $1 \leq p_j \leq 10^9$ ) — the profit you get inviting the $j$ -th model to the tour.

The next $m$ lines each contain $n$ integers. Line number $i$ contains $n$ integers $r_{i, j}$ ( $1 \leq r_{i, j} \leq n$ ) — the ratings of models in city $i$ .

输出格式

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
C++ 编辑器
输入
输出