Codeforces Round #625 (Div. 2, based on Technocup 2020 Final Round)B. Journey Planning

B. Journey Planning
time limit per test2 seconds
memory limit per test256 megabytes
inputstandard input
outputstandard output
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?

Input
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.

Output
Print one integer — the maximum beauty of a journey Tanya can choose.

Examples
inputCopy
6
10 7 1 9 10 15
outputCopy
26
inputCopy
1
400000
outputCopy
400000
inputCopy
7
8 9 26 11 12 29 14
outputCopy
55
Note
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].

题意:就是说给了n个数 数组b 然后要求你随便选下标ci
要满足c_(i+1)-c_i=b_(i+1)-b_i 就可以把对应的b_i和b_(i+1)相加 i和i+1可以不连续

思路:我们把式子转换成文字 就是
位置2-位置1=数字2-数字1 移项得 数字1-位置1=数字2-位置2=k
我们把k相同得加起来 取个最大值就是要求的答案了
注意k可能是负数 多加个值化正即可
其实直接写map更简单点 比赛时候没想那么多 想到什么就只管敲了

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define me(a,x) memset(a,x,sizeof a)
#define rep(i,x,n) for(int i=x;i<n;i++)
#define repd(i,x,n) for(int i=x;i<=n;i++)
#define all(x) (x).begin(), (x).end()
#define pb(a) push_back(a)
#define paii pair<int,int>
#define pali pair<ll,int>
#define pail pair<int,ll>
#define pall pair<ll,ll>
#define fi first
#define se second
vector<ll> a(200005);
vector<int> mp[800005];
int w=400000;
int main()
{
    int n;cin>>n;
    repd(i,1,n){
         cin>>a[i];
         int k=a[i]-i;
          mp[k+w].push_back(i);
    }
    ll ma=-1;
    for(int i=0;i<=800000;i++){
        if(mp[i].size()){
            ll sum=0;
            for(int j=0;j<mp[i].size();j++) sum+=a[mp[i][j]];
            ma=max(ma,sum);
        }
    }
    cout<<ma<<endl;


   return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

我不会c语言

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值