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> arr;
int sort_index[101010];
void init(int N, vector<int> H) {
n = N;
vector< pair<int, int> > temp;
for (int i = 0; i < N; i++) arr.push_back(H[i]);
for (int i = 0; i < N; i++) temp.push_back({H[i], i});
sort(temp.begin(), temp.end());
for (int i = 0; i < N; i++) {
sort_index[i] = temp[i].second;
}
}
int ch[101010];
int max_towers(int L, int R, int D) {
int ans = 0;
for (int i = 0; i < n; i++) ch[i] = 0;
for (int i = 0; i < n; i++) {
if (sort_index[i] < L || sort_index[i] > R) continue;
bool f = true;
int maxval = 0;
for (int j = sort_index[i] + 1; j <= R; j++) {
if (ch[j] == 1) {
if (maxval < max(arr[sort_index[i]], arr[j]) + D) f = false;
break;
}
maxval = max(maxval, arr[j]);
}
maxval = 0;
for (int j = sort_index[i] - 1; j >= L; j--) {
if (ch[j] == 1) {
if (maxval < max(arr[sort_index[i]], arr[j]) + D) f = false;
break;
}
maxval = max(maxval, arr[j]);
}
if (f) {
ans++;
ch[sort_index[i]] = 1;
}
}
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... |