CF2244G.Yura and Deadlines
普及+/提高
通过率:0%
时间限制:2.00s
内存限制:512MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Yura has n homework assignments. For each assignment, its weight ai is known — the number of course points Yura will receive if he completes it.
Yura wants to choose a subset of assignments to maximize the total number of points. However, he has one problem: some assignments are too time-consuming. If Yura works on two assignments at positions i and j (i=j), there must be enough other assignments between them; otherwise, he will get distracted and fail to complete them.
Formally, for any two chosen assignments with indices i and j, the following condition must hold: ∣i−j∣>max(ai,aj).
Find the maximum total weight Yura can obtain by choosing a subset of assignments satisfying this condition.
尤拉有 n 项家庭作业。对于每项作业,其权重 ai 是已知的——即尤拉完成该项作业所能获得的课程分数。
尤拉希望选择一个作业子集,以使总分最大化。但他面临一个问题:某些作业耗时过长。如果尤拉同时处理位置分别为 i 和 j(i=j)的两项作业,则它们之间必须存在足够多的其他作业;否则,他将分心并无法完成这两项作业。
形式化地说,对任意两个被选中的、索引分别为 i 和 j 的作业,必须满足以下条件:∣i−j∣>max(ai,aj)。
求尤拉在满足该条件的前提下,所能获得的最大总权重。
输入格式
The first line contains a single integer t (1≤t≤104) — the number of test cases.
The first line of each test case contains a single integer n (1≤n≤2⋅105) — the size of the array a.
The second line contains n integers a1,a2,…,an (0≤ai≤109) — the elements of the array.
It is guaranteed that the sum of n over all test cases does not exceed 2⋅105.
第一行包含一个整数 t(1≤t≤104)——测试用例的数量。
每个测试用例的第一行包含一个整数 n(1≤n≤2⋅105)——数组 a 的大小。
第二行包含 n 个整数 a1,a2,…,an(0≤ai≤109)——数组的元素。
保证所有测试用例的 n 之和不超过 2⋅105。
输出格式
For each test case, output a single integer — the maximum total weight of the selected assignments.
对于每个测试用例,输出一个整数——所选作业的总权重的最大值。
输入输出样例
输入#1
3 5 3 1 1 1 3 3 2 1 2 7 4 1 5 1 1 4 1
输出#1
6 2 8
说明/提示
In the first example, it is optimal to choose assignments with indices 1 and 5.
In the third example, it is optimal to choose assignments with indices 1 and 6.
在第一个例子中,选择索引为 1 和 5 的作业是最优的。
在第三个例子中,选择索引为 1 和 6 的作业是最优的。
输入解题思路,AI测评打分。不知道怎么写?