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>
using namespace std;
int n;
vector <int> h;
void init(int N, vector<int> H) {
n = N;
h = H;
}
int max_towers(int L, int R, int D) {
bool has = true;
int lst = 2e9;
int ans = 0;
for (int i = L; i <= R; i++) {
if (has) {
if (lst < h[i]) lst = max(lst, h[i]);
else if (h[i] <= lst - D) {
has = false;
lst = h[i];
ans++;
}
} else {
if (lst > h[i]) lst = min(lst, h[i]);
else if (h[i] - D >= lst) {
has = true;
lst = h[i];
}
}
}
return ans;
}
//main() {
// vector <int> cur = {10, 20, 60, 40, 50, 30, 70};
// init((int) cur.size(), cur);
// cout << max_towers(1, 5, 10) << '\n';
// cout << max_towers(2, 2, 10) << '\n';
// cout << max_towers(0, 6, 17) << '\n';
//}
# | 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... |