Codeforces Round #625 (Div. 2, based on Technocup 2020 Final Round) B. Journey Planning(映射)

题意:

已知 n 所城市(从 1 至 n 编号)及其美丽值,选取一条旅行路线,满足路线中两两城市美丽值之差等于编号之差,求所有旅行路线中美丽值的最大值。

思路:

美丽值与编号作差,差值为键,映射累加 。 

#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n;cin>>n;
    int b[n];for(int &i:b) cin>>i;
    map<int,long long> _map;
    for(int i=0;i<n;i++)
        _map[b[i]-i]+=b[i];
    long long mx=0;
    for(auto &i:_map)
        mx=max(mx,i.second);
    cout<<mx;
    return 0;
}

猜你喜欢

转载自www.cnblogs.com/Kanoon/p/12519897.html