Submission #644066

# Submission time Handle Problem Language Result Execution time Memory
644066 2022-09-23T17:42:25 Z Alexandruabcde Money (IZhO17_money) C++14
0 / 100
1 ms 212 KB
#include <bits/stdc++.h>

using namespace std;

constexpr int NMAX = 1e6 + 5;

int N;
int A[NMAX];

set <int> S;

int main () {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    cin >> N;

    for (int i = 1; i <= N; ++ i )
        cin >> A[i];

    int ans = 0;

    for (int i = 1; i <= N; ++ i ) {
        ++ ans;
        int j = i + 1;

        if (S.empty()) {
            for (; j <= N && A[j+1] >= A[j]; ++ j );

            for (int k = i; k <= j; ++ k )
                S.insert(A[k]);
            i = j;

            continue;
        }

        auto it = S.upper_bound(A[i]);

        if (it == S.end()) {
            for (; j <= N && A[j+1] >= A[j]; ++ j );

            for (int k = i; k <= j; ++ k )
                S.insert(A[k]);
            i = j;

            continue;
        }

        for (; j <= N && A[j+1] >= A[j] && A[j+1] < *it; ++ j );

        for (int k = i; k <= j; ++ k )
            S.insert(A[k]);
        i = j;
    }

    cout << ans << '\n';

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Incorrect 1 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Incorrect 1 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Incorrect 1 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Incorrect 1 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -