# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
874627 | sleepntsheep | Mountain Trek Route (IZhO12_route) | C++17 | 1 ms | 512 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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);
cout << s.back() << ' ' << i << endl;
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 |
---|---|---|---|---|
Fetching results... |