54502023-06-11 16:06:08HoraLegmesszebbi rossz sorrendű (35 pont)cpp11Accepted 35/3537ms6520 KiB
#include <bits/stdc++.h>
using namespace std;

int main() {
  int n;
  cin >> n;
  vector<int> szam(n);
  vector<int> maxi(n, -100001);
  vector<int> mini(n, 100001);
  cin >> szam[0];
  maxi[0] = szam[0];
  for(int i = 1; i < n; i++){
    cin >> szam[i];
    maxi[i] = max(szam[i], maxi[i - 1]);
  }
  mini[n - 1] = szam[n - 1];
  for(int i = n - 2; i >= 0; i--){
    mini[i] = min(szam[i], mini[i + 1]);
  }
  int bal = 0, jobb = 1;
  int maxdis = 0, maxb = -1, maxj = 0;
  while(bal < n){
    while(jobb < n && mini[jobb] <= maxi[bal]){
      jobb++;
    }
    if(jobb == n && mini[jobb - 1] >= maxi[bal]){
      bal++;
      continue;
    }
    if(maxdis < jobb - bal && mini[jobb - 1] < maxi[bal]){
      maxdis = jobb - bal;
      maxb = bal;
      maxj = jobb - 1;
    }
    bal++;
  }
  if(maxb == -1 || maxb == maxj) cout << -1;
  else cout << maxb + 1 << " " << maxj + 1;
}
SubtaskSumTestVerdictTimeMemory
base35/35
1Accepted0/03ms1688 KiB
2Accepted0/037ms4244 KiB
3Accepted1/13ms2064 KiB
4Accepted1/13ms2272 KiB
5Accepted1/13ms2512 KiB
6Accepted1/12ms2600 KiB
7Accepted1/13ms2580 KiB
8Accepted1/13ms2716 KiB
9Accepted1/13ms2964 KiB
10Accepted1/14ms3296 KiB
11Accepted1/14ms3384 KiB
12Accepted2/217ms3924 KiB
13Accepted2/218ms4188 KiB
14Accepted2/219ms4300 KiB
15Accepted2/213ms4036 KiB
16Accepted2/219ms4452 KiB
17Accepted2/228ms4784 KiB
18Accepted2/229ms5492 KiB
19Accepted2/232ms5672 KiB
20Accepted2/235ms5888 KiB
21Accepted2/237ms6472 KiB
22Accepted2/237ms6456 KiB
23Accepted2/235ms6456 KiB
24Accepted2/235ms6520 KiB