#include "towers.h"
#include <bits/stdc++.h>
using namespace std;
#define chmax(a, b) a = max(a, b)
#define pb push_back
const int maxn = 1e5 + 4;
int n;
int h[maxn];
int dp[maxn];
int pre[maxn];
int local_min(int i) {
if (1 <= i-1 && h[i] > h[i-1]) return 0;
if (i+1 <= n && h[i] > h[i+1]) return 0;
return 1;
}
void init(int N, std::vector<int> H) {
n = N;
for (int i=1; i<=n; i++) h[i] = H[i-1];
for (int i=1; i<=n; i++) pre[i] = pre[i-1] + local_min(i);
}
int max_towers(int L, int R, int D) {
if (L==R) return 1;
L++; R++;
int mx = 0;
vector<int> stk{h[L]};
for (int i = L+1; i <= R; i++) {
if (h[i] <= mx-D && stk.back() <= mx-D) stk.pb(h[i]);
else if (h[i] < stk.back()) {
stk.pop_back();
stk.pb(h[i]);
}
}
return stk.size();
}
# | 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... |