Codeforces - 1321B - Journey Planning(思维)

题目链接
题目大意:让你找出一列数,他们中相邻的两个数的下标之差等于数值之差。求这列数的最大值
  思路很简单,因为所得数列满足相邻的两个数的下标之差等于数值之差。所以只要让每个输入的数减去对应的下标所得到的下标指向的数加上这个数即可,如果两个数的下标之差等于数值之差,那么
它们各自的数减去下标所得到的下标指向的必定是同一个位置。换句话说,这个位置的数等于所有两个数的下标之差等于数值之差的数的和。(这样的位置可以有多个)

//https://www.cnblogs.com/shuitiangong/
#include<set>
#include<map>
#include<list>
#include<stack>
#include<queue>
#include<cmath>
#include<cstdio>
#include<cctype>
#include<string>
#include<vector>
#include<climits>
#include<cstring>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#define endl '\n'
#define rtl rt<<1
#define rtr rt<<1|1
#define lson rt<<1, l, mid
#define rson rt<<1|1, mid+1, r
#define zero(a) memset(a, 0, sizeof(a))
#define INF(a) memset(a, 0x3f, sizeof(a))
#define IOS ios::sync_with_stdio(false)
#define _test printf("==================================================\n")
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> P2;
const double pi = acos(-1.0);
const double eps = 1e-7;
const ll MOD =  998244353;
const int INF = 0x3f3f3f3f;
const int maxn = 1e6+10;
ll arr[maxn];
int main(void) {
    IOS; int n;
    const int top = 2e5+10;
    while(cin>>n) {
        ll ans = 0, num;
        for (int i = 1; i<=n; ++i) {
            cin >> num;
            arr[top+num-i] += num;
            ans = max(ans, arr[top+num-i]);
        }
        cout << ans << endl;
    }
    return 0;
}

猜你喜欢

转载自www.cnblogs.com/shuitiangong/p/12573257.html