CF1936C.Pokémon Arena

提高+/省选-

通过率:0%

时间限制:3.00s

内存限制:512MB

AC君温馨提醒

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

题目描述

You are at a dueling arena. You also possess nn Pokémons. Initially, only the 11-st Pokémon is standing in the arena.

Each Pokémon has mm attributes. The jj-th attribute of the ii-th Pokémon is ai,ja_{i,j}. Each Pokémon also has a cost to be hired: the ii-th Pokémon's cost is cic_i.

You want to have the nn-th Pokémon stand in the arena. To do that, you can perform the following two types of operations any number of times in any order:

  • Choose three integers ii, jj, kk (1≤i≤n1 \le i \le n, 1≤j≤m1 \le j \le m, k>0k \gt 0), increase ai,ja_{i,j} by kk permanently. The cost of this operation is kk.
  • Choose two integers ii, jj (1≤i≤n1 \le i \le n, 1≤j≤m1 \le j \le m) and hire the ii-th Pokémon to duel with the current Pokémon in the arena based on the jj-th attribute. The ii-th Pokémon will win if ai,ja_{i,j} is greater than or equal to the jj-th attribute of the current Pokémon in the arena (otherwise, it will lose). After the duel, only the winner will stand in the arena. The cost of this operation is cic_i.

Find the minimum cost you need to pay to have the nn-th Pokémon stand in the arena.

你身处一个决斗竞技场。你拥有 nn 只宝可梦。初始时,只有第 11 只宝可梦站在竞技场中。

每只宝可梦有 mm 项属性。第 ii 只宝可梦的第 jj 项属性为 ai,ja_{i,j}。每只宝可梦还有一个雇佣成本:第 ii 只宝可梦的成本为 cic_i。

你的目标是让第 nn 只宝可梦最终站在竞技场中。为此,你可以以任意顺序、任意次数执行以下两类操作:

  • 选择三个整数 ii、jj、kk(满足 1≤i≤n1 \le i \le n,1≤j≤m1 \le j \le m,k>0k > 0),将 ai,ja_{i,j} 永久增加 kk。该操作的成本为 kk。
  • 选择两个整数 ii、jj(满足 1≤i≤n1 \le i \le n,1≤j≤m1 \le j \le m),雇佣第 ii 只宝可梦,使其基于第 jj 项属性与当前在竞技场中的宝可梦进行决斗。若第 ii 只宝可梦的第 jj 项属性 ai,ja_{i,j} 大于或等于当前竞技场中宝可梦的第 jj 项属性,则第 ii 只宝可梦获胜(否则失败)。决斗结束后,仅胜者留在竞技场中。该操作的成本为 cic_i。

求使第 nn 只宝可梦最终站在竞技场中所需支付的最小总成本。

输入格式

Each test contains multiple test cases. The first line contains the number of test cases tt (1≤t≤1051 \le t \le 10^5). The description of the test cases follows.

The first line of each test case contains two integers nn and mm (2≤n≤4⋅1052 \le n \le 4 \cdot 10^5, 1≤m≤2⋅1051 \le m \le 2 \cdot 10^5, 2≤n⋅m≤4⋅1052 \leq n \cdot m \leq 4 \cdot 10^5).

The second line of each test case contains nn integers c1,c2,…,cnc_1, c_2, \ldots, c_n (1≤ci≤1091 \le c_i \le 10^9).

The ii-th of the following nn lines contains mm integers ai,1,ai,2,…,ai,ma_{i,1}, a_{i,2}, \ldots, a_{i,m} (1≤ai,j≤1091 \le a_{i,j} \le 10^9).

It is guaranteed that the sum of n⋅mn \cdot m over all test cases does not exceed 4⋅1054 \cdot 10^5.

每个测试包含多个测试用例。第一行包含测试用例的数量 tt(1≤t≤1051 \le t \le 10^5)。随后是各测试用例的描述。

每个测试用例的第一行包含两个整数 nn 和 mm(2≤n≤4⋅1052 \le n \le 4 \cdot 10^5,1≤m≤2⋅1051 \le m \le 2 \cdot 10^5,2≤n⋅m≤4⋅1052 \leq n \cdot m \leq 4 \cdot 10^5)。

每个测试用例的第二行包含 nn 个整数 c1,c2,…,cnc_1, c_2, \ldots, c_n(1≤ci≤1091 \le c_i \le 10^9)。

接下来的 nn 行中,第 ii 行包含 mm 个整数 ai,1,ai,2,…,ai,ma_{i,1}, a_{i,2}, \ldots, a_{i,m}(1≤ai,j≤1091 \le a_{i,j} \le 10^9)。

保证所有测试用例中 n⋅mn \cdot m 的总和不超过 4⋅1054 \cdot 10^5。

输出格式

For each test case, output the minimum cost to make the nn-th Pokémon stand in the arena.

对于每个测试用例,输出使第 nn 只宝可梦站在竞技场中的最小代价。

输入输出样例

  • 输入#1

    4
    3 3
    2 3 1
    2 9 9
    6 1 7
    1 2 1
    3 3
    2 3 1
    9 9 9
    6 1 7
    1 2 1
    4 2
    2 8 3 5
    18 24
    17 10
    1 10
    1 1
    6 3
    21412674 3212925 172015806 250849370 306960171 333018900
    950000001 950000001 950000001
    821757276 783362401 760000001
    570000001 700246226 600757652
    380000001 423513575 474035234
    315201473 300580025 287023445
    1 1 1

    输出#1

    2
    6
    17
    1224474550

说明/提示

In the first test case, the attribute array of the 11-st Pokémon (which is standing in the arena initially) is [2,9,9][2,9,9].

In the first operation, you can choose i=3i=3, j=1j=1, k=1k=1, and increase a3,1a_{3,1} by 11 permanently. Now the attribute array of the 33-rd Pokémon is [2,2,1][2,2,1]. The cost of this operation is k=1k = 1.

In the second operation, you can choose i=3i=3, j=1j=1, and hire the 33-rd Pokémon to duel with the current Pokémon in the arena based on the 11-st attribute. Since ai,j=a3,1=2≥2=a1,1a_{i,j}=a_{3,1}=2 \ge 2=a_{1,1}, the 33-rd Pokémon will win. The cost of this operation is c3=1c_3 = 1.

Thus, we have made the 33-rd Pokémon stand in the arena within the cost of 22. It can be proven that 22 is minimum possible.

In the second test case, the attribute array of the 11-st Pokémon in the arena is [9,9,9][9,9,9].

In the first operation, you can choose i=2i=2, j=3j=3, k=2k=2, and increase a2,3a_{2,3} by 22 permanently. Now the attribute array of the 22-nd Pokémon is [6,1,9][6,1,9]. The cost of this operation is k=2k = 2.

In the second operation, you can choose i=2i=2, j=3j=3, and hire the 22-nd Pokémon to duel with the current Pokémon in the arena based on the 33-rd attribute. Since ai,j=a2,3=9≥9=a1,3a_{i,j}=a_{2,3}=9 \ge 9=a_{1,3}, the 22-nd Pokémon will win. The cost of this operation is c2=3c_2 = 3.

In the third operation, you can choose i=3i=3, j=2j=2, and hire the 33-rd Pokémon to duel with the current Pokémon in the arena based on the 22-nd attribute. Since ai,j=a1,2=2≥1=a2,2a_{i,j}=a_{1,2}=2 \ge 1=a_{2,2}, the 33-rd Pokémon can win. The cost of this operation is c3=1c_3 = 1.

Thus, we have made the 33-rd Pokémon stand in the arena within the cost of 66. It can be proven that 66 is minimum possible.

在第一个测试用例中,初始站在竞技场中的第 11 只宝可梦的属性数组为 [2,9,9][2,9,9]。

在第一次操作中,你可以选择 i=3i=3、j=1j=1、k=1k=1,将 a3,1a_{3,1} 永久增加 11。此时第 33 只宝可梦的属性数组变为 [2,2,1][2,2,1]。该操作的代价为 k=1k = 1。

在第二次操作中,你可以选择 i=3i=3、j=1j=1,雇佣第 33 只宝可梦,依据第 11 项属性与当前竞技场中的宝可梦进行对决。由于 ai,j=a3,1=2≥2=a1,1a_{i,j}=a_{3,1}=2 \ge 2=a_{1,1},第 33 只宝可梦获胜。该操作的代价为 c3=1c_3 = 1。

因此,我们以总代价 22 成功使第 33 只宝可梦站在了竞技场中。可以证明 22 是可能的最小代价。

在第二个测试用例中,初始站在竞技场中的第 11 只宝可梦的属性数组为 [9,9,9][9,9,9]。

在第一次操作中,你可以选择 i=2i=2、j=3j=3、k=2k=2,将 a2,3a_{2,3} 永久增加 22。此时第 22 只宝可梦的属性数组变为 [6,1,9][6,1,9]。该操作的代价为 k=2k = 2。

在第二次操作中,你可以选择 i=2i=2、j=3j=3,雇佣第 22 只宝可梦,依据第 33 项属性与当前竞技场中的宝可梦进行对决。由于 ai,j=a2,3=9≥9=a1,3a_{i,j}=a_{2,3}=9 \ge 9=a_{1,3},第 22 只宝可梦获胜。该操作的代价为 c2=3c_2 = 3。

在第三次操作中,你可以选择 i=3i=3、j=2j=2,雇佣第 33 只宝可梦,依据第 22 项属性与当前竞技场中的宝可梦进行对决。由于 ai,j=a1,2=2≥1=a2,2a_{i,j}=a_{1,2}=2 \ge 1=a_{2,2},第 33 只宝可梦获胜。该操作的代价为 c3=1c_3 = 1。

因此,我们以总代价 66 成功使第 33 只宝可梦站在了竞技场中。可以证明 66 是可能的最小代价。

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

首页