CF2244G.Yura and Deadlines

普及+/提高

通过率:0%

时间限制:2.00s

内存限制:512MB

AC君温馨提醒

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

题目描述

Yura has nn homework assignments. For each assignment, its weight aia_i 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 ii and jj (i≠ji \neq 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 ii and jj, the following condition must hold: ∣i−j∣>max⁡(ai,aj)|i - j| \gt \max(a_i, a_j).

Find the maximum total weight Yura can obtain by choosing a subset of assignments satisfying this condition.

尤拉有 nn 项家庭作业。对于每项作业,其权重 aia_i 是已知的——即尤拉完成该项作业所能获得的课程分数。

尤拉希望选择一个作业子集,以使总分最大化。但他面临一个问题:某些作业耗时过长。如果尤拉同时处理位置分别为 ii 和 jj(i≠ji \neq j)的两项作业,则它们之间必须存在足够多的其他作业;否则,他将分心并无法完成这两项作业。

形式化地说,对任意两个被选中的、索引分别为 ii 和 jj 的作业,必须满足以下条件:∣i−j∣>max⁡(ai,aj)|i - j| \gt \max(a_i, a_j)。

求尤拉在满足该条件的前提下,所能获得的最大总权重。

输入格式

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

The first line of each test case contains a single integer nn (1≤n≤2⋅1051 \le n \le 2 \cdot 10^5) — the size of the array aa.

The second line contains nn integers a1,a2,…,ana_1, a_2, \dots, a_n (0≤ai≤1090 \le a_i \le 10^9) — the elements of the array.

It is guaranteed that the sum of nn over all test cases does not exceed 2⋅1052 \cdot 10^5.

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

每个测试用例的第一行包含一个整数 nn(1≤n≤2⋅1051 \le n \le 2 \cdot 10^5)——数组 aa 的大小。

第二行包含 nn 个整数 a1,a2,…,ana_1, a_2, \dots, a_n(0≤ai≤1090 \le a_i \le 10^9)——数组的元素。

保证所有测试用例的 nn 之和不超过 2⋅1052 \cdot 10^5。

输出格式

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 11 and 55.

In the third example, it is optimal to choose assignments with indices 11 and 66.

在第一个例子中,选择索引为 11 和 55 的作业是最优的。

在第三个例子中,选择索引为 11 和 66 的作业是最优的。

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

首页