Submission #874628

# Submission time Handle Problem Language Result Execution time Memory
874628 2023-11-17T12:37:43 Z sleepntsheep Mountain Trek Route (IZhO12_route) C++17
0 / 100
1 ms 348 KB
#include <iostream>
#include <cassert>
#include <cstring>
#include <vector>
#include <algorithm>
#include <deque>
#include <set>
#include <utility>
#include <array>

using i64 = long long;
using u64 = unsigned long long;
using f64 = double;
using f80 = long double;

using namespace std;
#define ALL(x) x.begin(), x.end()
#define ShinLena cin.tie(nullptr)->sync_with_stdio(false);
#define N 1000000

int z, n, k; i64 a[N+3];

int main()
{
    ShinLena;
    cin >> n >> k;
    a[0] = a[n+2] = 1e18+1;
    for (int i = 1; i <= n; ++i) cin >> a[i];
    a[n+1] = a[0];
    n += 3;

    deque<i64> v; deque<int> s = {0};
    for (int i = 1; i < n; ++i)
    {
        for (; s.size() && a[s.back()] <= a[i]; )
        {
            if (a[s.back()] == 1e18+1 && a[i] == 1e18+1) break;
            v.push_back(i - s.back() - 1);
            s.pop_back();
        }
        s.push_back(i);
    }

    sort(ALL(v));
    for (; v.size() && v[0] == 0; ) v.pop_front();
    for (; v.size() && k >= v[0]; )
        z += 2, k -= v[0], v.pop_front();

    cout << z;

    return 0;
}


# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Incorrect 0 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -