fork download
  1. #include <iostream>
  2. #include<bits/stdc++.h>
  3. using namespace std;
  4.  
  5. int main() {
  6. int n ; cin>>n;
  7. vector<int>arr(n);
  8. for(int i = 0 ; i<n;i++) cin>>arr[i];
  9. unordered_map<int,int>hash;
  10. int sum = 0 ; int max_sum =INT_MIN;
  11. for(int i = 0 ; i<n;i++){
  12. hash[arr[i]-i]+=arr[i];
  13. max_sum= max(hash[arr[i]-i],max_sum);
  14. }
  15. cout<<max_sum;
  16.  
  17. // your code goes here
  18. return 0;
  19. }
Success #stdin #stdout 0.01s 5320KB
stdin
3
1 2 3 
stdout
6