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 <vector>
#ifndef EVAL
#include <format>
#include <iostream>
template <typename... Args>
void print(std::format_string<Args...> fmt, Args &&...args) {
std::cerr << std::format(fmt, std::forward<Args>(args)...);
}
template <typename... Args>
void println(std::format_string<Args...> fmt, Args &&...args) {
std::cerr << std::format(fmt, std::forward<Args>(args)...) << '\n';
}
#else
template <typename... T> void print(T &&...args) {}
template <typename... T> void println(T &&...args) {}
#endif
int n;
std::vector<int> h;
void init(int N, std::vector<int> H) {
n = N;
h = H;
}
int max_towers(int L, int R, int D) {
if (L == R)
return 1;
R += 1;
std::vector<int> included{h[L]};
int greatest = h[L];
for (int i = L + 1; i < R; i++) {
if (h[i] > greatest) {
// println("Found new intermediary: {}", h[i]);
greatest = h[i];
} else if (greatest - included.back() < D) {
if (h[i] < included.back()) {
// println("Found better tower: {} instead of {}", h[i], included.back());
included.pop_back();
included.push_back(h[i]);
greatest = h[i];
} else {
// println("Found new tower, but it's worse: {} instead of {}", h[i], included.back());
}
} else if (greatest - h[i] >= D) {
// println("Found new tower: {} (previous was {}, greatest: {})", h[i], included.back(), greatest);
included.push_back(h[i]);
greatest = h[i];
}
}
return included.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... |