54492023-06-11 16:04:15HoraLegmesszebbi rossz sorrendű (35 pont)cpp11Accepted 35/3537ms6152 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];
  //cout << maxi[0] << " ";
  for(int i = 1; i < n; i++){
    cin >> szam[i];
    maxi[i] = max(szam[i], maxi[i - 1]);
    //cout << maxi[i] << " ";
  }
  //cout << "\n";
  mini[n - 1] = szam[n - 1];
  //cout << mini[n - 1] << " ";
  for(int i = n - 2; i >= 0; i--){
    mini[i] = min(szam[i], mini[i + 1]);
    //cout << mini[i] << " ";
  }
  //cout << "\n";
  int bal = 0, jobb = 1;
  int maxdis = 0, maxb = -1, maxj = 0;
  while(bal < n){
    while(jobb < n && mini[jobb] <= maxi[bal]){
      jobb++;
      //cout << "bal: " << bal << " jobb: " << jobb << "\n";
    }
    if(jobb == n && mini[jobb - 1] >= maxi[bal]){
      bal++;
      continue;
    }
    //cout << bal << " " << jobb;
    //cout << "\n" << jobb - bal << "\n";
    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/03ms1708 KiB
2Accepted0/037ms4200 KiB
3Accepted1/13ms2140 KiB
4Accepted1/13ms2356 KiB
5Accepted1/13ms2600 KiB
6Accepted1/13ms2684 KiB
7Accepted1/13ms2684 KiB
8Accepted1/13ms2792 KiB
9Accepted1/13ms3040 KiB
10Accepted1/14ms3100 KiB
11Accepted1/14ms3440 KiB
12Accepted2/216ms4068 KiB
13Accepted2/218ms4200 KiB
14Accepted2/219ms4220 KiB
15Accepted2/213ms3960 KiB
16Accepted2/219ms4188 KiB
17Accepted2/227ms4804 KiB
18Accepted2/230ms5204 KiB
19Accepted2/234ms5388 KiB
20Accepted2/235ms5388 KiB
21Accepted2/237ms5980 KiB
22Accepted2/237ms5936 KiB
23Accepted2/234ms6064 KiB
24Accepted2/235ms6152 KiB