209192026-01-11 13:15:09hunzombiInverziócpp17Wrong answer 9/50187ms6288 KiB
#include <bits/stdc++.h>
using namespace std;

int main()
{
    int n;
    cin >> n;
    vector<int> arr(n + 1, 0);
    vector<int> prefMax(n + 1, 0);
    for (int i=1; i <= n; i++) {
        cin >> arr[i];
        prefMax[i] = max(prefMax[i - 1], arr[i]);
    }
    vector<int> suffMin(n + 2, 1e8);
    for (int i=n; i > 0; i--) {
        suffMin[i] = min(suffMin[i + 1], arr[i]);
    }

    int low = 1, high = n;
    int best_dist = -1;
    int best_i = -1, best_j = -1;
    while (low < high) {
        if (prefMax[low] > suffMin[high]) {
            if (high - low > best_dist) {
                best_dist = high - low;
                best_i = low;
                best_j = high;
            }
            high--;
        } else {
            low++;
        }
    }

    if (best_dist == -1) {
        cout << -1;
    } else {
        cout << best_i << ' ' << best_j;
    }
    return 0;
}
SubtaskSumTestVerdictTimeMemory
base9/50
1Accepted0/01ms316 KiB
2Wrong answer0/017ms804 KiB
3Accepted1/11ms316 KiB
4Accepted2/21ms316 KiB
5Wrong answer0/71ms316 KiB
6Accepted2/217ms804 KiB
7Wrong answer0/2187ms6120 KiB
8Wrong answer0/2185ms6120 KiB
9Accepted2/2186ms6124 KiB
10Wrong answer0/2187ms6124 KiB
11Wrong answer0/2186ms6120 KiB
12Wrong answer0/2181ms5976 KiB
13Wrong answer0/2187ms6128 KiB
14Wrong answer0/2186ms6124 KiB
15Wrong answer0/2187ms6196 KiB
16Wrong answer0/2186ms6196 KiB
17Wrong answer0/2185ms6124 KiB
18Wrong answer0/2185ms6124 KiB
19Wrong answer0/3186ms6196 KiB
20Wrong answer0/3187ms6196 KiB
21Wrong answer0/2185ms6128 KiB
22Wrong answer0/2185ms6288 KiB
23Wrong answer0/2187ms6124 KiB
24Accepted2/2187ms6120 KiB