제출 #1352313

#제출 시각아이디문제언어결과실행 시간메모리
1352313kawhiet지구 온난화 (NOI13_gw)C++20
23 / 40
132 ms8392 KiB
#include <bits/stdc++.h>
using namespace std;

#ifdef LOCAL
#include "debug.h"
#else
#define dbg(...) 47
#endif

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin >> n;
    vector<array<int, 2>> h(n);
    for (int i = 0; i < n; i++) {
        cin >> h[i][0];
        h[i][1] = i;
    }
    sort(h.rbegin(), h.rend());
    vector<bool> vis(n);
    int ans = 0, s = 0;
    for (int i = 0; i < n; i++) {
        int j = h[i][1];
        bool ok = true;
        if (j > 0 && vis[j - 1]) ok = false;
        if (j + 1 < n && vis[j + 1]) ok = false;
        if (ok) {
            s++;
        }
        if (j > 0 && j < n - 1 && vis[j - 1] && vis[j + 1]) {
            s--;
        }
        vis[j] = 1;
        ans = max(ans, s);
    }
    cout << ans << '\n';
    return 0;
}
#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...