Submission #1030059

#TimeUsernameProblemLanguageResultExecution timeMemory
1030059jnjwnwnwGlobal Warming (NOI13_gw)C++17
19 / 40
994 ms65192 KiB
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>

using namespace std;

#define ll int
#define fff(i, a, b) for(ll i = a; i < b; i++)

#define MAXN 1000006

bool sim[MAXN];
map<ll, ll> cntOf;

int main(){
    ll n; cin >> n;
    vector<pair<ll, ll>> v;
    fff(i, 0, n){
        ll a; cin >> a;
        cntOf[a]++;
        v.emplace_back(a, i+1);
    }
    sort(v.rbegin(), v.rend());

    ll best = 0;
    ll cur = 0;
    fff(i, 0, n){
        auto [h, j] = v[i];
        cntOf[h]--;
        sim[j] = 1;
        cur++;
        if (sim[j+1]) cur--;
        if (sim[j-1]) cur--;
        if (!cntOf[h] && cur > best) best = cur;
    }
    cout << best << endl;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...