Codeforces Round #625 (Div. 2, based on Technocup 2020 Final Round)---B. Journey Planning(1400水公式)

简介: 算法

21.png

题意:给你个数组b,要你要求出来他所能构造的另外一个数组的和,构造条件是用b数组里的数并且b数组里的下标差要等于b数组里值的差,并且必须得是上升序列

思路:

把公式转换一下即可:i-j=bi-bj 并且i>j,交换一下i-bi=j-bj,所以我去数组里找下标和值差中和最多的值输出,注意为负的情况,开longlong

#include<bits/stdc++.h>
using namespace std;
#define int long long 
const int maxn=2e5+100;
int b[maxn];
signed main()
{
    int n,i,j,t;
        cin>>n;
        map<int ,int >m1;
        for(i=1;i<=n;i++)
        {
            cin>>b[i];
            m1[b[i]-i]+=b[i];
        }
        int ans=0;
        for(auto x:m1)
        {
            ans=max(ans,x.second);
        }
        cout<<ans<<endl;
    return 0;
}


相关文章
|
6月前
Codeforces Round #192 (Div. 2) (330B) B.Road Construction
要将N个城市全部相连,刚开始以为是最小生成树的问题,其实就是一道简单的题目。 要求两个城市之间不超过两条道路,那么所有的城市应该是连在一个点上的,至于这个点就很好找了,只要找到一个没有和其他点有道路限制的即可。
18 0
|
机器学习/深度学习 人工智能 BI
Educational Codeforces Round 115 (Rated for Div. 2) D. Training Session(组合数学 思维)
Educational Codeforces Round 115 (Rated for Div. 2) D. Training Session(组合数学 思维)
82 0
|
人工智能 Windows
Educational Codeforces Round 113 (Rated for Div. 2) C - Jury Meeting (思维 组合数)
Educational Codeforces Round 113 (Rated for Div. 2) C - Jury Meeting (思维 组合数)
72 0
|
人工智能
Educational Codeforces Round 113 (Rated for Div. 2) B. Chess Tournament(思维 构造)
Educational Codeforces Round 113 (Rated for Div. 2) B. Chess Tournament(思维 构造)
67 0
|
人工智能
Educational Codeforces Round 33
A. Chess For Three time limit per test1 second memory limit per test256 megabytes inputstanda...
1143 0
|
人工智能
Educational Codeforces Round 31 A B C
A. Book Reading time limit per test2 seconds memory limit per test256 megabytes inputstandard...
1079 0