209212026-01-11 14:04:06hunzombiInverziócpp17Accepted 50/50179ms4532 KiB
#include <bits/stdc++.h>
using namespace std;

int main()
{
    int n;
    cin >> n;
    vector<int> arr(n + 1, 0);
    for (int i=0; i < n; i++) cin >> arr[i];

    vector<int> st;
    for (int i=0; i < n; i++) {
        if (st.empty() || arr[i] > arr[st.back()]) {
            st.push_back(i);
        }
    }

    int bestDist = -1;
    int best_i = -1, best_j = -1;

    for (int j = n - 1; j >= 0; j--) {
        while (!st.empty() && arr[st.back()] > arr[j]) {
            int i = st.back();
            st.pop_back();

            if (j - i > bestDist) {
                bestDist = j - i;
                best_i = i;
                best_j = j;
            }
        }
    }

    if (bestDist == -1) {
        cout << -1 << '\n';
    } else {
        cout << best_i + 1 << ' ' << best_j + 1 << '\n';
    }

    return 0;
}
SubtaskSumTestVerdictTimeMemory
base50/50
1Accepted0/01ms500 KiB
2Accepted0/017ms608 KiB
3Accepted1/11ms508 KiB
4Accepted2/21ms316 KiB
5Accepted7/71ms404 KiB
6Accepted2/217ms568 KiB
7Accepted2/2173ms2364 KiB
8Accepted2/2173ms2360 KiB
9Accepted2/2174ms2356 KiB
10Accepted2/2173ms2152 KiB
11Accepted2/2174ms2356 KiB
12Accepted2/2171ms2100 KiB
13Accepted2/2173ms2356 KiB
14Accepted2/2172ms2356 KiB
15Accepted2/2174ms2356 KiB
16Accepted2/2175ms2356 KiB
17Accepted2/2173ms2356 KiB
18Accepted2/2173ms2356 KiB
19Accepted3/3173ms2356 KiB
20Accepted3/3173ms2552 KiB
21Accepted2/2173ms2356 KiB
22Accepted2/2173ms2356 KiB
23Accepted2/2174ms2356 KiB
24Accepted2/2179ms4532 KiB