Codeforces 1321B Journey Planning

题目链接

题意是给你一个数组(b), (c)是从(1到n),找到一个子集([c_1, c_2,···, c_k]),满足(c_i>c_{i-1}, c_i-c_{i-1} = b_{c_i}-b_{c_{i-1}}), 使得(b_{c_i})的和最大
那我们可以转换一下等式, (c_i-b_{c_i} = c_{i-1}-b_{c_{i-1}}), 也就是说根据(c与b)分组,求和最大的一组

#include<bits/stdc++.h>
using namespace std;
#define ms(x,y) memset(x, y, sizeof(x))
#define lowbit(x) ((x)&(-x))
typedef long long LL;
typedef pair<int,int> pii;

const int maxn = 6e6+7;

int buf[maxn];
LL ans[maxn];

void run_case() {
    int n; cin >> n;
    for(int i = 1; i <= n; ++i) {
        int t; cin >> t;
        ans[t - i + 200000] += t;
    }
    LL ret = 0;
    for(int i = 0; i < maxn; ++i)
        ret = max(ret, ans[i]);
    cout << ret;
}

int main() {
    ios::sync_with_stdio(false), cin.tie(0);
    cout.flags(ios::fixed);cout.precision(2);
    //int t; cin >> t;
    //while(t--)
    run_case();
    cout.flush();
    return 0;
}
原文地址:https://www.cnblogs.com/GRedComeT/p/12442814.html