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 "towers.h"
#include <bits/stdc++.h>
using namespace std;
int n;
vector<int> a;
void init(int N, std::vector<int> H) {
n = N;
a = H;
}
int max_towers(int L, int R, int D) {
vector<vector<int>> srt;
for(int i = L; i <= R; ++i){
srt.push_back({a[i], i});
}
sort(srt.begin(), srt.end());
vector<int> chk(n);
for(int i = 0; i < (int)srt.size(); ++i){
int now = srt[i][1];
if(now < L || now > R){
continue;
}
int r = now + 1, can = 1;
while(r <= R && a[r] < a[now] + D){
if(chk[r]){
can = 0;
break;
}
++r;
}
int l = now - 1;
while(l >= L && a[l] < a[now] + D){
if(chk[l]){
can = 0;
break;
}
--l;
}
chk[now] = can;
}
return accumulate(chk.begin(), chk.end(), 0ll);
}
# | 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... |