题目链接:https://vjudge.net/contest/399382#problem/B 题解:相同一串的满足的条件是bj-bi=j-i,所以通过移项可以得到bj-j=bi-i,所以是个一对一关系,所以自然想到了map,相同的累加即可,最后得出最大值输出。 代码:
#include<iostream>
#include<map>
#include<string>
#include<algorithm>
#define maxx 400000
using namespace std
;
typedef long long ll
;
map
<ll
,ll
>m
;
int main()
{
int n
;
scanf("%d",&n
);
ll t
;
ll maxn
=-1*0x3f3f3f3f;
for(int i
=0;i
<n
;i
++)
{
scanf("%lld",&t
);
m
[t
-i
]+=t
;
maxn
=max(maxn
,m
[t
-i
]);
}
cout
<<maxn
<<endl
;
return 0;
}
转载请注明原文地址:https://blackberry.8miu.com/read-33542.html