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 pb push_back
#define mp make_pair
int n,arr[100001];
int k;
void init(int N,vector<int> H){
n=N;
for (int i=1;i<=n;i++){
arr[i]=H[i-1];
}
k=1;
while (k<=n && arr[k+1]>arr[k]){
k++;
}
for (int i=k+1;i<=n;i++){
if (arr[i]>arr[i-1]){
k=-1;
}
}
}
int max_towers(int l,int r,int d){
l++;
r++;
if (k!=-1){
if (l>=k || r<=k) return 1;
if (arr[l]<=arr[k]-d && arr[r]<=arr[k]-d) return 2;
return 1;
}
int ans=1,smol=arr[l],tall=arr[l];
for (int i=l+1;i<=r;i++){
if (tall<smol+d){
smol=min(smol,arr[i]);
tall=arr[i];
}
tall=max(tall,arr[i]);
if (tall>=smol+d && tall>=arr[i]+d){
smol=arr[i];
tall=arr[i];
ans++;
}
}
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... |