ACWing 2014.岛

ACWing 2014.岛

题目

在这里插入图片描述

思路

代码

#include<bits/stdc++.h>
typedef long long LL;

using namespace std;
const int N = 100005,M = 1e9+1;
int a[N];
map<int ,int >b;
int n;
int main()
{
    
    
    cin >> n;

    for (int i = 1; i <= n; i ++ ){
    
    
        cin >> a[i];
        if(a[i]>a[i-1]){
    
    
            //数的大小在[a[i-1],a[i]-1]之间的所有数大小都+1
            b[a[i-1]]++,b[a[i]]--;
        }
    }
    LL sum = 0 ,res = 0;
    for (auto i:b ){
    
    
        //求前缀和
        sum+=i.second;
        res = max(res,sum);
    }
    cout << res;
}

猜你喜欢

转载自blog.csdn.net/m0_63388363/article/details/129986995
今日推荐