CF1917C.Watering an Array
普及/提高-
通过率:0%
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,…] .
输入格式
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 .
输出格式
For each test case, output one integer: the maximum score you can achieve at the end of the d -th day.
输入输出样例
输入#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.