CF1936C.Pokémon Arena
提高+/省选-
通过率:0%
时间限制:3.00s
内存限制:512MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You are at a dueling arena. You also possess n Pokémons. Initially, only the 1-st Pokémon is standing in the arena.
Each Pokémon has m attributes. The j-th attribute of the i-th Pokémon is ai,j. Each Pokémon also has a cost to be hired: the i-th Pokémon's cost is ci.
You want to have the n-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 i, j, k (1≤i≤n, 1≤j≤m, k>0), increase ai,j by k permanently. The cost of this operation is k.
- Choose two integers i, j (1≤i≤n, 1≤j≤m) and hire the i-th Pokémon to duel with the current Pokémon in the arena based on the j-th attribute. The i-th Pokémon will win if ai,j is greater than or equal to the j-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 ci.
Find the minimum cost you need to pay to have the n-th Pokémon stand in the arena.
你身处一个决斗竞技场。你拥有 n 只宝可梦。初始时,只有第 1 只宝可梦站在竞技场中。
每只宝可梦有 m 项属性。第 i 只宝可梦的第 j 项属性为 ai,j。每只宝可梦还有一个雇佣成本:第 i 只宝可梦的成本为 ci。
你的目标是让第 n 只宝可梦最终站在竞技场中。为此,你可以以任意顺序、任意次数执行以下两类操作:
- 选择三个整数 i、j、k(满足 1≤i≤n,1≤j≤m,k>0),将 ai,j 永久增加 k。该操作的成本为 k。
- 选择两个整数 i、j(满足 1≤i≤n,1≤j≤m),雇佣第 i 只宝可梦,使其基于第 j 项属性与当前在竞技场中的宝可梦进行决斗。若第 i 只宝可梦的第 j 项属性 ai,j 大于或等于当前竞技场中宝可梦的第 j 项属性,则第 i 只宝可梦获胜(否则失败)。决斗结束后,仅胜者留在竞技场中。该操作的成本为 ci。
求使第 n 只宝可梦最终站在竞技场中所需支付的最小总成本。
输入格式
Each test contains multiple test cases. The first line contains the number of test cases t (1≤t≤105). The description of the test cases follows.
The first line of each test case contains two integers n and m (2≤n≤4⋅105, 1≤m≤2⋅105, 2≤n⋅m≤4⋅105).
The second line of each test case contains n integers c1,c2,…,cn (1≤ci≤109).
The i-th of the following n lines contains m integers ai,1,ai,2,…,ai,m (1≤ai,j≤109).
It is guaranteed that the sum of n⋅m over all test cases does not exceed 4⋅105.
每个测试包含多个测试用例。第一行包含测试用例的数量 t(1≤t≤105)。随后是各测试用例的描述。
每个测试用例的第一行包含两个整数 n 和 m(2≤n≤4⋅105,1≤m≤2⋅105,2≤n⋅m≤4⋅105)。
每个测试用例的第二行包含 n 个整数 c1,c2,…,cn(1≤ci≤109)。
接下来的 n 行中,第 i 行包含 m 个整数 ai,1,ai,2,…,ai,m(1≤ai,j≤109)。
保证所有测试用例中 n⋅m 的总和不超过 4⋅105。
输出格式
For each test case, output the minimum cost to make the n-th Pokémon stand in the arena.
对于每个测试用例,输出使第 n 只宝可梦站在竞技场中的最小代价。
输入输出样例
输入#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 1-st Pokémon (which is standing in the arena initially) is [2,9,9].
In the first operation, you can choose i=3, j=1, k=1, and increase a3,1 by 1 permanently. Now the attribute array of the 3-rd Pokémon is [2,2,1]. The cost of this operation is k=1.
In the second operation, you can choose i=3, j=1, and hire the 3-rd Pokémon to duel with the current Pokémon in the arena based on the 1-st attribute. Since ai,j=a3,1=2≥2=a1,1, the 3-rd Pokémon will win. The cost of this operation is c3=1.
Thus, we have made the 3-rd Pokémon stand in the arena within the cost of 2. It can be proven that 2 is minimum possible.
In the second test case, the attribute array of the 1-st Pokémon in the arena is [9,9,9].
In the first operation, you can choose i=2, j=3, k=2, and increase a2,3 by 2 permanently. Now the attribute array of the 2-nd Pokémon is [6,1,9]. The cost of this operation is k=2.
In the second operation, you can choose i=2, j=3, and hire the 2-nd Pokémon to duel with the current Pokémon in the arena based on the 3-rd attribute. Since ai,j=a2,3=9≥9=a1,3, the 2-nd Pokémon will win. The cost of this operation is c2=3.
In the third operation, you can choose i=3, j=2, and hire the 3-rd Pokémon to duel with the current Pokémon in the arena based on the 2-nd attribute. Since ai,j=a1,2=2≥1=a2,2, the 3-rd Pokémon can win. The cost of this operation is c3=1.
Thus, we have made the 3-rd Pokémon stand in the arena within the cost of 6. It can be proven that 6 is minimum possible.
在第一个测试用例中,初始站在竞技场中的第 1 只宝可梦的属性数组为 [2,9,9]。
在第一次操作中,你可以选择 i=3、j=1、k=1,将 a3,1 永久增加 1。此时第 3 只宝可梦的属性数组变为 [2,2,1]。该操作的代价为 k=1。
在第二次操作中,你可以选择 i=3、j=1,雇佣第 3 只宝可梦,依据第 1 项属性与当前竞技场中的宝可梦进行对决。由于 ai,j=a3,1=2≥2=a1,1,第 3 只宝可梦获胜。该操作的代价为 c3=1。
因此,我们以总代价 2 成功使第 3 只宝可梦站在了竞技场中。可以证明 2 是可能的最小代价。
在第二个测试用例中,初始站在竞技场中的第 1 只宝可梦的属性数组为 [9,9,9]。
在第一次操作中,你可以选择 i=2、j=3、k=2,将 a2,3 永久增加 2。此时第 2 只宝可梦的属性数组变为 [6,1,9]。该操作的代价为 k=2。
在第二次操作中,你可以选择 i=2、j=3,雇佣第 2 只宝可梦,依据第 3 项属性与当前竞技场中的宝可梦进行对决。由于 ai,j=a2,3=9≥9=a1,3,第 2 只宝可梦获胜。该操作的代价为 c2=3。
在第三次操作中,你可以选择 i=3、j=2,雇佣第 3 只宝可梦,依据第 2 项属性与当前竞技场中的宝可梦进行对决。由于 ai,j=a1,2=2≥1=a2,2,第 3 只宝可梦获胜。该操作的代价为 c3=1。
因此,我们以总代价 6 成功使第 3 只宝可梦站在了竞技场中。可以证明 6 是可能的最小代价。
输入解题思路,AI测评打分。不知道怎么写?