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 <bits/stdc++.h>
#include "towers.h"
#define ll long long
#define ar array
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
using namespace std;
template<typename T> bool ckmin(T &a, const T &b ) { return a > b ? a = b, 1 : 0; }
template<typename T> bool ckmax(T &a, const T &b ) { return a < b ? a = b, 1 : 0; }
int N; vector<int> h;
void init(int _N, std::vector<int> H) {
N = _N;
h = H;
}
int max_towers(int L, int R, int D) {
auto solve = [&](auto&& s, int l, int r, int lim) -> int {
if (l > r) return 0;
if (l == r) return h[l] <= lim;
int p = l;
for (int i = l+1; i <= r; i++) if (h[i] > h[p]) p = i;
return max(int(h[p] <= lim), s(s, l, p-1, min(lim, h[p] - D)) + s(s, p+1, r, min(lim, h[p] - D)));
};
return solve(solve, L, R, 1e9);
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |