CF1917C.Watering an Array
普及/提高-
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You have an array of integers a1,a2,…,an of length n. On the i-th of the next d days you are going to do exactly one of the following two actions:
- Add 1 to each of the first bi elements of the array a (i.e., set aj:=aj+1 for each 1≤j≤bi).
- Count the elements which are equal to their position (i.e., the aj=j). Denote the number of such elements as c. Then, you add c to your score, and reset the entire array a to a 0-array of length n (i.e., set [a1,a2,…,an]:=[0,0,…,0]).
Your score is equal to 0 in the beginning. Note that on each day you should perform exactly one of the actions above: you cannot skip a day or perform both actions on the same day.
What is the maximum score you can achieve at the end?
Since d can be quite large, the sequence b is given to you in the compressed format:
- You are given a sequence of integers v1,v2,…,vk. The sequence b is a concatenation of infinitely many copies of v: b=[v1,v2,…,vk,v1,v2,…,vk,…].
你有一个长度为 n 的整数数组 a1,a2,…,an。在接下来的 d 天中,第 i 天你恰好执行以下两种操作之一:
- 将数组 a 的前 bi 个元素各加 1(即对每个 1≤j≤bi,令 aj:=aj+1);
- 统计满足“元素值等于其位置下标”的元素个数(即满足 aj=j 的 j 的个数),记该数量为 c;然后将 c 加入你的得分,并将整个数组 a 重置为全零数组(即令 [a1,a2,…,an]:=[0,0,…,0])。
初始得分为 0。注意:每天必须且只能执行上述两个操作之一,不可跳过某天,也不可在同一天执行两个操作。
最终你能获得的最大得分是多少?
由于 d 可能非常大,序列 b 以压缩格式给出:
- 你将获得一个整数序列 v1,v2,…,vk;序列 b 是由无限次重复 v 得到的:b=[v1,v2,…,vk,v1,v2,…,vk,…]。
输入格式
The first line contains a single integer t (1≤t≤103) — the number of test cases.
The first line of each test case contains three integers n, k and d (1≤n≤2000, 1≤k≤105, k≤d≤109) — the length of the array a, the length of the sequence v and the number of days you are going to perform operations on.
The second line of each test case contains n integers a1,a2,…,an (0≤ai≤n) — the array a.
The third line of each test case contains k integers v1,v2,…,vk (1≤vi≤n) — the sequence v.
It is guaranteed that the sum of n over all test cases doesn't exceed 2000 and the sum of k over all test cases doesn't exceed 105.
第一行包含一个整数 t(1≤t≤103)—— 测试用例的数量。
每个测试用例的第一行包含三个整数 n、k 和 d(1≤n≤2000,1≤k≤105,k≤d≤109)—— 分别表示数组 a 的长度、序列 v 的长度,以及你将执行操作的天数。
每个测试用例的第二行包含 n 个整数 a1,a2,…,an(0≤ai≤n)—— 数组 a。
每个测试用例的第三行包含 k 个整数 v1,v2,…,vk(1≤vi≤n)—— 序列 v。
保证所有测试用例中 n 的总和不超过 2000,且所有测试用例中 k 的总和不超过 105。
输出格式
For each test case, output one integer: the maximum score you can achieve at the end of the d-th day.
对于每个测试用例,输出一个整数:在第 d 天结束时你能获得的最高分数。
输入输出样例
输入#1
5 3 4 4 1 2 3 1 3 2 3 6 2 3 6 1 2 4 1 5 6 6 5 1 1 0 5 0 5 0 5 1 1 1 1 1 3 4 6 1 2 3 1 3 2 3
输出#1
4 3 0 1 5
说明/提示
In the first test case, the sequence b is equal to [1,3,2,3,1,3,2,3,…] and one of the optimal solutions for this case is as follows:
- Perform the operation of the second type on the 1-st day: your score increases by 3 and array a becomes equal to [0,0,0].
- Perform the operation of the first type on the 2-nd day: array a becomes equal to [1,1,1].
- Perform the operation of the first type on the 3-rd day: array a becomes equal to [2,2,1].
- Perform the operation of the second type on the 4-th day: your score increases by 1 and array a becomes equal to [0,0,0].
It can be shown that it is impossible to score more than 4, so the answer is 4.
In the second test case, the sequence b is equal to [6,6,6,6,…]. One of the ways to score 3 is to perform operations of the first type on the 1-st and the 3-rd days and to perform an operation of the second type on the 2-nd day.
在第一个测试用例中,序列 b 等于 [1,3,2,3,1,3,2,3,…],该测试用例的一个最优解如下:
- 在第 1 天执行第二种操作:你的得分增加 3,数组 a 变为 [0,0,0]。
- 在第 2 天执行第一种操作:数组 a 变为 [1,1,1]。
- 在第 3 天执行第一种操作:数组 a 变为 [2,2,1]。
- 在第 4 天执行第二种操作:你的得分增加 1,数组 a 变为 [0,0,0]。
可以证明,不可能获得超过 4 的得分,因此答案为 4。
在第二个测试用例中,序列 b 等于 [6,6,6,6,…]。一种获得 3 分的方法是:在第 1 天和第 3 天执行第一种操作,在第 2 天执行第二种操作。
输入解题思路,AI测评打分。不知道怎么写?