310985: CF1917C. Watering an Array

Memory Limit:256 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

C. Watering an Arraytime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard output

You have an array of integers $a_1, a_2, \ldots, a_n$ 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 $b_i$ elements of the array $a$ (i.e., set $a_j := a_j + 1$ for each $1 \le j \le b_i$).
  • Count the elements which are equal to their position (i.e., the $a_j = 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 $[a_1, a_2, \ldots, a_n] := [0, 0, \ldots, 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 $v_1, v_2, \ldots, v_k$. The sequence $b$ is a concatenation of infinitely many copies of $v$: $b = [v_1, v_2, \ldots, v_k, v_1, v_2, \ldots, v_k, \ldots]$.
Input

The first line contains a single integer $t$ ($1 \le t \le 10^3$) — the number of test cases.

The first line of each test case contains three integers $n$, $k$ and $d$ ($1 \le n \le 2000$, $1 \le k \le 10^5$, $k \le d \le 10^9$) — 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 $a_1, a_2, \ldots, a_n$ ($0 \le a_i \le n$) — the array $a$.

The third line of each test case contains $k$ integers $v_1, v_2, \ldots, v_k$ ($1 \le v_i \le 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 $10^5$.

Output

For each test case, output one integer: the maximum score you can achieve at the end of the $d$-th day.

ExampleInput
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
Output
4
3
0
1
5
Note

In the first test case, the sequence $b$ is equal to $[1, 3, 2, 3, 1, 3, 2, 3, \ldots]$ 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, \ldots]$. 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.

Output

题目大意:给定一个长度为n的整数数组a1, a2, ..., an,在接下来的d天里,每天执行以下两个操作之一:

1. 将数组a的前bi个元素各加1(即对于每个1≤j≤bi,执行aj := aj + 1)。
2. 计算等于其位置的元素个数(即找出aj = j的元素个数),记为c。然后,将c加到你的得分上,并将整个数组a重置为长度为n的0数组(即设置[a1, a2, ..., an] := [0, 0, ..., 0])。

你的初始得分为0。注意,每天你应执行上述操作之一:不能跳过一天或在同一天执行两个操作。

问题是在d天后,你能获得的最大得分是多少?

输入数据格式:

- 第一行包含一个整数t(1≤t≤10^3),表示测试用例的数量。
- 每个测试用例的第一行包含三个整数n、k和d(1≤n≤2000,1≤k≤10^5,k≤d≤10^9),分别表示数组a的长度、序列v的长度和将要执行操作的天数。
- 每个测试用例的第二行包含n个整数a1, a2, ..., an(0≤ai≤n),表示数组a。
- 每个测试用例的第三行包含k个整数v1, v2, ..., vk(1≤vi≤n),表示序列v。
- 保证所有测试用例的n之和不超过2000,k之和不超过10^5。

输出数据格式:

- 对于每个测试用例,输出一个整数:你在第d天结束时能获得的最大得分。

示例输入:

```
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
```

示例输出:

```
4
3
0
1
5
```

注意:在第一个测试用例中,序列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天执行第二个操作。题目大意:给定一个长度为n的整数数组a1, a2, ..., an,在接下来的d天里,每天执行以下两个操作之一: 1. 将数组a的前bi个元素各加1(即对于每个1≤j≤bi,执行aj := aj + 1)。 2. 计算等于其位置的元素个数(即找出aj = j的元素个数),记为c。然后,将c加到你的得分上,并将整个数组a重置为长度为n的0数组(即设置[a1, a2, ..., an] := [0, 0, ..., 0])。 你的初始得分为0。注意,每天你应执行上述操作之一:不能跳过一天或在同一天执行两个操作。 问题是在d天后,你能获得的最大得分是多少? 输入数据格式: - 第一行包含一个整数t(1≤t≤10^3),表示测试用例的数量。 - 每个测试用例的第一行包含三个整数n、k和d(1≤n≤2000,1≤k≤10^5,k≤d≤10^9),分别表示数组a的长度、序列v的长度和将要执行操作的天数。 - 每个测试用例的第二行包含n个整数a1, a2, ..., an(0≤ai≤n),表示数组a。 - 每个测试用例的第三行包含k个整数v1, v2, ..., vk(1≤vi≤n),表示序列v。 - 保证所有测试用例的n之和不超过2000,k之和不超过10^5。 输出数据格式: - 对于每个测试用例,输出一个整数:你在第d天结束时能获得的最大得分。 示例输入: ``` 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 ``` 示例输出: ``` 4 3 0 1 5 ``` 注意:在第一个测试用例中,序列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天执行第二个操作。

加入题单

上一题 下一题 算法标签: