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"
using namespace std;
using ll = long long;
int n;
vector<int> h, ix;
void init(int N, std::vector<int> H) {
n = N, h = H;
ix.resize(n);
iota(ix.begin(), ix.end(), 0);
sort(ix.begin(), ix.end(), [&](int i, int j) {
return h[i] < h[j];
});
}
int max_towers(int L, int R, int D) {
int res = 0;
for (int i_ = 0; i_ < n; i_++) {
int i = ix[i_];
if (i < L || i > R) continue;
bool ok = 1;
for (int j = i; j >= L; j--) {
if (h[j] < h[i]) {
ok = 0; break;
}
else if (h[j] - h[i] >= D)
break;
}
for (int j = i; j <= R; j++) {
if (h[j] < h[i]) {ok = 0;break;}
else if (h[j] - h[i] >= D) break;
}
res += ok;
}
return res;
}
# | 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... |