CF1917C.Watering an Array

普及/提高-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

You have an array of integers a1,a2,…,ana_1, a_2, \ldots, a_n of length nn. On the ii-th of the next dd days you are going to do exactly one of the following two actions:

  • Add 11 to each of the first bib_i elements of the array aa (i.e., set aj:=aj+1a_j := a_j + 1 for each 1≤j≤bi1 \le j \le b_i).
  • Count the elements which are equal to their position (i.e., the aj=ja_j = j). Denote the number of such elements as cc. Then, you add cc to your score, and reset the entire array aa to a 00-array of length nn (i.e., set [a1,a2,…,an]:=[0,0,…,0][a_1, a_2, \ldots, a_n] := [0, 0, \ldots, 0]).

Your score is equal to 00 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 dd can be quite large, the sequence bb is given to you in the compressed format:

  • You are given a sequence of integers v1,v2,…,vkv_1, v_2, \ldots, v_k. The sequence bb is a concatenation of infinitely many copies of vv: b=[v1,v2,…,vk,v1,v2,…,vk,…]b = [v_1, v_2, \ldots, v_k, v_1, v_2, \ldots, v_k, \ldots].

你有一个长度为 nn 的整数数组 a1,a2,…,ana_1, a_2, \ldots, a_n。在接下来的 dd 天中,第 ii 天你恰好执行以下两种操作之一:

  • 将数组 aa 的前 bib_i 个元素各加 11(即对每个 1≤j≤bi1 \le j \le b_i,令 aj:=aj+1a_j := a_j + 1);
  • 统计满足“元素值等于其位置下标”的元素个数(即满足 aj=ja_j = j 的 jj 的个数),记该数量为 cc;然后将 cc 加入你的得分,并将整个数组 aa 重置为全零数组(即令 [a1,a2,…,an]:=[0,0,…,0][a_1, a_2, \ldots, a_n] := [0, 0, \ldots, 0])。

初始得分为 00。注意:每天必须且只能执行上述两个操作之一,不可跳过某天,也不可在同一天执行两个操作。

最终你能获得的最大得分是多少?

由于 dd 可能非常大,序列 bb 以压缩格式给出:

  • 你将获得一个整数序列 v1,v2,…,vkv_1, v_2, \ldots, v_k;序列 bb 是由无限次重复 vv 得到的:b=[v1,v2,…,vk,v1,v2,…,vk,…]b = [v_1, v_2, \ldots, v_k, v_1, v_2, \ldots, v_k, \ldots]。

输入格式

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

The first line of each test case contains three integers nn, kk and dd (1≤n≤20001 \le n \le 2000, 1≤k≤1051 \le k \le 10^5, k≤d≤109k \le d \le 10^9) — the length of the array aa, the length of the sequence vv and the number of days you are going to perform operations on.

The second line of each test case contains nn integers a1,a2,…,ana_1, a_2, \ldots, a_n (0≤ai≤n0 \le a_i \le n) — the array aa.

The third line of each test case contains kk integers v1,v2,…,vkv_1, v_2, \ldots, v_k (1≤vi≤n1 \le v_i \le n) — the sequence vv.

It is guaranteed that the sum of nn over all test cases doesn't exceed 20002000 and the sum of kk over all test cases doesn't exceed 10510^5.

第一行包含一个整数 tt(1≤t≤1031 \le t \le 10^3)—— 测试用例的数量。

每个测试用例的第一行包含三个整数 nn、kk 和 dd(1≤n≤20001 \le n \le 2000,1≤k≤1051 \le k \le 10^5,k≤d≤109k \le d \le 10^9)—— 分别表示数组 aa 的长度、序列 vv 的长度,以及你将执行操作的天数。

每个测试用例的第二行包含 nn 个整数 a1,a2,…,ana_1, a_2, \ldots, a_n(0≤ai≤n0 \le a_i \le n)—— 数组 aa。

每个测试用例的第三行包含 kk 个整数 v1,v2,…,vkv_1, v_2, \ldots, v_k(1≤vi≤n1 \le v_i \le n)—— 序列 vv。

保证所有测试用例中 nn 的总和不超过 20002000,且所有测试用例中 kk 的总和不超过 10510^5。

输出格式

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

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

输入输出样例

  • 输入#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 bb is equal to [1,3,2,3,1,3,2,3,…][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 11-st day: your score increases by 33 and array aa becomes equal to [0,0,0][0, 0, 0].
  • Perform the operation of the first type on the 22-nd day: array aa becomes equal to [1,1,1][1, 1, 1].
  • Perform the operation of the first type on the 33-rd day: array aa becomes equal to [2,2,1][2, 2, 1].
  • Perform the operation of the second type on the 44-th day: your score increases by 11 and array aa becomes equal to [0,0,0][0, 0, 0].

It can be shown that it is impossible to score more than 44, so the answer is 44.

In the second test case, the sequence bb is equal to [6,6,6,6,…][6, 6, 6, 6, \ldots]. One of the ways to score 33 is to perform operations of the first type on the 11-st and the 33-rd days and to perform an operation of the second type on the 22-nd day.

在第一个测试用例中,序列 bb 等于 [1,3,2,3,1,3,2,3,…][1, 3, 2, 3, 1, 3, 2, 3, \ldots],该测试用例的一个最优解如下:

  • 在第 11 天执行第二种操作:你的得分增加 33,数组 aa 变为 [0,0,0][0, 0, 0]。
  • 在第 22 天执行第一种操作:数组 aa 变为 [1,1,1][1, 1, 1]。
  • 在第 33 天执行第一种操作:数组 aa 变为 [2,2,1][2, 2, 1]。
  • 在第 44 天执行第二种操作:你的得分增加 11,数组 aa 变为 [0,0,0][0, 0, 0]。

可以证明,不可能获得超过 44 的得分,因此答案为 44。

在第二个测试用例中,序列 bb 等于 [6,6,6,6,…][6, 6, 6, 6, \ldots]。一种获得 33 分的方法是:在第 11 天和第 33 天执行第一种操作,在第 22 天执行第二种操作。

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

首页