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;
#define ll long long
#define pb push_back
#define ff first
#define ss second
#define all(s) s.begin(),s.end()
#define rall(s) s.rbegin(),s.rend()
int n;
vector<int>h;
vector<pair<int,int>>v;
vector<bool>used;
void init(int N,vector<int>H){
n=N; h=H;
used.resize(n);
for(int i=0;i<n;i++){
v.pb({H[i],i});
}
sort(all(h));
}
int max_towers(int L,int R,int D){
fill(all(used),0);
int ans=0;
for(auto [x,i]:v){
if(x<L||x>R) continue;
bool add=true;
int mx=0;
for(int j=i-1;j>=L;j--){
if(used[j]){
if(mx<x+D){
add=false;
}
}
mx=max(mx,h[j]);
}
mx=0;
for(int j=i+1;j<=R;j++){
if(used[j]){
if(mx<x+D){
add=false;
}
}
mx=max(mx,h[j]);
}
if(add){
ans++;
used[i]=true;
}
}
return ans;
}
# | 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... |