56092023-08-07 14:10:36TomaSajtVölgy (100 pont)cpp17Accepted 100/10039ms11068 KiB
#include <bits/stdc++.h>
using namespace std;

int n;

int solve(const vector<int>& heights) {
  int best_width = 0;
  vector<int> prev(n);
  prev[0] = -1;
  for (int i = 1; i < n; i++) {
    prev[i] = i - 1;
    while (prev[i] != -1 && heights[i] > heights[prev[i]]) prev[i] = prev[prev[i]];
    if (prev[i] != -1) best_width = max(best_width, i - prev[i]);
  }
  return best_width;
}

int main() {
  cin >> n;
  vector<int> heights(n);
  for (int& h : heights) cin >> h;
  int res1 = solve(heights);
  reverse(heights.begin(), heights.end());
  int res = max(res1, solve(heights));
  if (res < 2) {
    cout << -1;
    return 0;
  }
  cout << res;
}
SubtaskSumTestVerdictTimeMemory
base100/100
1Accepted0/03ms1812 KiB
2Accepted0/03ms1940 KiB
3Accepted5/53ms2084 KiB
4Accepted5/53ms2332 KiB
5Accepted5/52ms2384 KiB
6Accepted5/53ms2636 KiB
7Accepted5/52ms2756 KiB
8Accepted5/52ms2756 KiB
9Accepted5/53ms2896 KiB
10Accepted5/53ms3112 KiB
11Accepted5/54ms3252 KiB
12Accepted5/54ms3480 KiB
13Accepted5/56ms3688 KiB
14Accepted5/56ms3968 KiB
15Accepted5/534ms5840 KiB
16Accepted5/537ms6568 KiB
17Accepted5/535ms7172 KiB
18Accepted5/535ms7636 KiB
19Accepted5/535ms8456 KiB
20Accepted5/539ms9180 KiB
21Accepted5/539ms10068 KiB
22Accepted5/539ms11068 KiB