输入样例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
简单变动一下便是哈希,一开始用dp推了好半天也没做出来
#include <iostream>
#include <vector>
#include <map>
using ll = long long;
using namespace std;
int main()
{
int n,x;
ll res=-1;
cin>>n;
map<int, ll> b;
for (int i = 1; i <= n; i ++ ){
scanf("%d", &x);
b[x-i] += x;
}
for (auto& [i,j]: b){
res=max(res,b[i]);
}
cout << res;
return 0;
}