225842026-01-15 11:38:05PappMatyasInverziócpp17Time limit exceeded 41/50580ms2556 KiB
#include<iostream>
#include<algorithm>
#include<vector>

using namespace std;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int n;
    cin >> n;
    vector<int> v(n);

    for (int i = 0; i < n; i++)
    {
        cin >> v[i];
    }

    for (int i = n - 1; i >= 0; i--)
    {
        if (i + 1 == v[i])
        {
            v.pop_back();
        }
        else
        {
            break;
        }
    }
    int b = -1, e = -1;
    int maxLength = 0;
    int maxi = -1;
    for (int i = 0; i < n - maxLength - 1; i++)
    {
        if (v[i] < maxi)
        {
            continue;
        }
        for (int j = n - 1; j > i + maxLength; j--)
        {
            if (v[i] > v[j])
            {
                if (j - i > e - b)
                {
                    b = i + 1;
                    e = j + 1;
                    maxLength = e - b;
                    break;
                }

            }
        }
        maxi = max(maxi, v[i]);
    }
    if (e != -1)
    {
        cout << b << " " << e;
    }
    else
    {
        cout << -1;
    }
}
SubtaskSumTestVerdictTimeMemory
base41/50
1Accepted0/01ms500 KiB
2Accepted0/014ms564 KiB
3Accepted1/12ms316 KiB
4Accepted2/21ms316 KiB
5Accepted7/71ms316 KiB
6Accepted2/26ms564 KiB
7Time limit exceeded0/2551ms2328 KiB
8Accepted2/257ms2356 KiB
9Accepted2/261ms2356 KiB
10Accepted2/259ms2356 KiB
11Accepted2/261ms2356 KiB
12Accepted2/257ms2100 KiB
13Accepted2/261ms2360 KiB
14Accepted2/259ms2556 KiB
15Accepted2/2333ms2356 KiB
16Accepted2/259ms2196 KiB
17Accepted2/257ms2356 KiB
18Accepted2/261ms2356 KiB
19Accepted3/3360ms2360 KiB
20Time limit exceeded0/3507ms2356 KiB
21Time limit exceeded0/2575ms2356 KiB
22Accepted2/259ms2356 KiB
23Accepted2/259ms2356 KiB
24Time limit exceeded0/2580ms2380 KiB