CF1320A.Journey Planning
普及/提高-
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Tanya wants to go on a journey across the cities of Berland. There are n cities situated along the main railroad line of Berland, and these cities are numbered from 1 to n.
Tanya plans her journey as follows. First of all, she will choose some city c1 to start her journey. She will visit it, and after that go to some other city c2>c1, then to some other city c3>c2, and so on, until she chooses to end her journey in some city ck>ck−1. So, the sequence of visited cities [c1,c2,…,ck] should be strictly increasing.
There are some additional constraints on the sequence of cities Tanya visits. Each city i has a beauty value bi associated with it. If there is only one city in Tanya's journey, these beauty values imply no additional constraints. But if there are multiple cities in the sequence, then for any pair of adjacent cities ci and ci+1, the condition ci+1−ci=bci+1−bci must hold.
For example, if n=8 and b=[3,4,4,6,6,7,8,9], there are several three possible ways to plan a journey:
- c=[1,2,4];
- c=[3,5,6,8];
- c=[7] (a journey consisting of one city is also valid).
There are some additional ways to plan a journey that are not listed above.
Tanya wants her journey to be as beautiful as possible. The beauty value of the whole journey is the sum of beauty values over all visited cities. Can you help her to choose the optimal plan, that is, to maximize the beauty value of the journey?
塔尼娅想要在贝尔兰的各个城市之间进行一次旅行。贝尔兰的主铁路线上共有 n 座城市,这些城市沿铁路线依次编号为 1 到 n。
塔尼娅计划她的旅行如下:首先,她将选择某座城市 c1 作为旅行起点;她会访问该城市,然后前往另一座编号更大的城市 c2>c1,再前往另一座编号更大的城市 c3>c2,依此类推,直到她在某座城市 ck>ck−1 结束旅行。因此,所访问城市的序列 [c1,c2,…,ck] 必须是严格递增的。
对塔尼娅所访问的城市序列还有一些额外约束。每座城市 i 都有一个对应的美丽值 bi。若塔尼娅的旅行仅包含一座城市,则这些美丽值不带来任何额外约束;但若序列中包含多座城市,则对任意一对相邻城市 ci 和 ci+1,必须满足条件:
ci+1−ci=bci+1−bci.
例如,当 n=8 且 b=[3,4,4,6,6,7,8,9] 时,存在以下三种可能的旅行方案:
- c=[1,2,4];
- c=[3,5,6,8];
- c=[7](仅含一座城市的旅行也是合法的)。
此外,还存在一些未在此列出的其他合法旅行方案。
塔尼娅希望她的旅行尽可能美丽。整段旅行的美丽值定义为所有被访问城市美丽值之和。你能帮她选出最优方案,即最大化旅行美丽值吗?
输入格式
The first line contains one integer n (1≤n≤2⋅105) — the number of cities in Berland.
The second line contains n integers b1, b2, ..., bn (1≤bi≤4⋅105), where bi is the beauty value of the i-th city.
第一行包含一个整数 n(1≤n≤2⋅105)—— 表示 Berland 的城市数量。
第二行包含 n 个整数 b1, b2, ..., bn(1≤bi≤4⋅105),其中 bi 表示第 i 个城市的美丽值。
输出格式
Print one integer — the maximum beauty of a journey Tanya can choose.
输出一个整数——塔尼娅可选择的旅程的最大美丽值。
输入输出样例
输入#1
6 10 7 1 9 10 15
输出#1
26
输入#2
1 400000
输出#2
400000
输入#3
7 8 9 26 11 12 29 14
输出#3
55
说明/提示
The optimal journey plan in the first example is c=[2,4,5].
The optimal journey plan in the second example is c=[1].
The optimal journey plan in the third example is c=[3,6].
第一个示例中的最优旅行计划为 c=[2,4,5]。
第二个示例中的最优旅行计划为 c=[1]。
第三个示例中的最优旅行计划为 c=[3,6]。
输入解题思路,AI测评打分。不知道怎么写?