254812026-02-20 11:50:04SzeredaiNatanaelLegmesszebbi rossz sorrendű (35 pont)python3Runtime error 0/3516ms3144 KiB
#include <iostream>
#include <vector>

using namespace std;

int main()
{
	int n, mini = 100001, maxi = -100001;
	cin >> n;
	vector<int> v(n + 1);
	vector<int> ma(n + 1);
	vector<int> mi(n + 1);
	
	for (int i = 1; i <= n; ++i) {
		cin >> v[i];

		if (v[i] > maxi) {
			maxi = v[i];
		}
		ma[i] = maxi;
	}
	for (int j = n; j > 0; --j) {
		if (v[j] < mini) {
			mini = v[j];
		}
		mi[j] = mini;
	}

	int i = 1, j = 1, p = -1, p2 = -1, t, maxit = 0;
	while (j <= n && i <= n) {
		if (ma[i] > mi[j]) {
			++j;
		}
		else {
			t = j - 1 - i;
			if (t > maxit) {
				maxit = t;
				p = j - 1;
				p2 = i;
			}
			while (ma[i] < mi[j]) ++i;
		}
	}

	if (p == -1) {
		cout << "-1";
	}
	else {
		cout << p2 << " " << p;
	}
}
SubtaskSumTestVerdictTimeMemory
base0/35
1Runtime error0/016ms2868 KiB
2Runtime error0/014ms2860 KiB
3Runtime error0/114ms2868 KiB
4Runtime error0/116ms2868 KiB
5Runtime error0/116ms3036 KiB
6Runtime error0/114ms2980 KiB
7Runtime error0/116ms2868 KiB
8Runtime error0/114ms3040 KiB
9Runtime error0/116ms2868 KiB
10Runtime error0/116ms3056 KiB
11Runtime error0/116ms2864 KiB
12Runtime error0/216ms3060 KiB
13Runtime error0/216ms2868 KiB
14Runtime error0/216ms3040 KiB
15Runtime error0/216ms2868 KiB
16Runtime error0/216ms3144 KiB
17Runtime error0/216ms2820 KiB
18Runtime error0/214ms3052 KiB
19Runtime error0/214ms3012 KiB
20Runtime error0/216ms2884 KiB
21Runtime error0/214ms2916 KiB
22Runtime error0/216ms2808 KiB
23Runtime error0/214ms3068 KiB
24Runtime error0/216ms2884 KiB