CF1826D.Running Miles

普及+/提高

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

There is a street with nn sights, with sight number ii being ii miles from the beginning of the street. Sight number ii has beauty bib_i. You want to start your morning jog ll miles and end it rr miles from the beginning of the street. By the time you run, you will see sights you run by (including sights at ll and rr miles from the start). You are interested in the 33 most beautiful sights along your jog, but every mile you run, you get more and more tired.

So choose ll and rr, such that there are at least 33 sights you run by, and the sum of beauties of the 33 most beautiful sights minus the distance in miles you have to run is maximized. More formally, choose ll and rr, such that bi1+bi2+bi3−(r−l)b_{i_1} + b_{i_2} + b_{i_3} - (r - l) is maximum possible, where i1,i2,i3i_1, i_2, i_3 are the indices of the three maximum elements in range [l,r][l, r].

街道上有 nn 个景点,其中第 ii 个景点距离街道起点 ii 英里。第 ii 个景点的美观度为 bib_i。你希望从距离街道起点 ll 英里处开始晨跑,并在距离起点 rr 英里处结束。跑步过程中,你会经过(包括端点)所有位于区间 [l,r][l, r] 内的景点。你特别关注此次跑步路线上美观度最高的 33 个景点,但每跑一英里,你的疲劳程度都会递增。

因此,请选择 ll 和 rr,使得你经过的景点数量至少为 33 个,且“这 33 个最美丽景点的美观度之和”减去“跑步总距离(英里)”的值最大化。更形式化地说,需选择 ll 和 rr,使得 bi1+bi2+bi3−(r−l)b_{i_1} + b_{i_2} + b_{i_3} - (r - l) 尽可能大,其中 i1,i2,i3i_1, i_2, i_3 是区间 [l,r][l, r] 内美观度最大的三个元素所对应的下标。

输入格式

The first line contains a single integer tt (1≤t≤1051 \leq t \leq 10^5) — the number of test cases.

The first line of each test case contains a single integer nn (3≤n≤1053 \leq n \leq 10^5).

The second line of each test case contains nn integers bib_i (1≤bi≤1081 \leq b_i \leq 10^8) — beauties of sights ii miles from the beginning of the street.

It's guaranteed that the sum of all nn does not exceed 10510^5.

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

每个测试用例的第一行包含一个整数 nn(3≤n≤1053 \leq n \leq 10^5)。

每个测试用例的第二行包含 nn 个整数 bib_i(1≤bi≤1081 \leq b_i \leq 10^8)—— 表示距离街道起点 ii 英里处景点的美观度。

保证所有 nn 的总和不超过 10510^5。

输出格式

For each test case output a single integer equal to the maximum value bi1+bi2+bi3−(r−l)b_{i_1} + b_{i_2} + b_{i_3} - (r - l) for some running range [l,r][l, r].

对于每个测试用例,输出一个整数,该整数等于在某个运行区间 [l,r][l, r] 上表达式 bi1+bi2+bi3−(r−l)b_{i_1} + b_{i_2} + b_{i_3} - (r - l) 的最大值。

输入输出样例

  • 输入#1

    4
    5
    5 1 4 2 3
    4
    1 1 1 1
    6
    9 8 7 6 5 4
    7
    100000000 1 100000000 1 100000000 1 100000000

    输出#1

    8
    1
    22
    299999996

说明/提示

In the first example, we can choose ll and rr to be 11 and 55. So we visit all the sights and the three sights with the maximum beauty are the sights with indices 11, 33, and 55 with beauties 55, 44, and 33, respectively. So the total value is 5+4+3−(5−1)=85 + 4 + 3 - (5 - 1) = 8.

In the second example, the range [l,r][l, r] can be [1,3][1, 3] or [2,4][2, 4], the total value is 1+1+1−(3−1)=11 + 1 + 1 - (3 - 1) = 1.

在第一个例子中,我们可以选择 ll 和 rr 分别为 11 和 55。因此我们游览了所有景点,其中美丽值最大的三处景点的下标分别为 11、33 和 55,其美丽值分别为 55、44 和 33。因此总价值为 5+4+3−(5−1)=85 + 4 + 3 - (5 - 1) = 8。

在第二个例子中,区间 [l,r][l, r] 可以为 [1,3][1, 3] 或 [2,4][2, 4],总价值为 1+1+1−(3−1)=11 + 1 + 1 - (3 - 1) = 1。

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

首页