29642023-02-06 10:15:09tamasmarkInverziócpp17Accepted 50/50259ms12104 KiB
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

struct adat
{
    int hely, poz;
};

int i, n, mini,kezd,veg;

bool comp(adat a, adat b)
{
    return a.poz > b.poz;
}

int main()
{
    cin >> n;

    vector <adat> x(n + 1);

    for (i = 1; i <= n; ++i)
    {
        cin >> x[i].poz;
        x[i].hely = i;
    }

    sort(x.begin() + 1, x.end(), comp);

    mini = x[1].hely;
    for (i = 2; i <= n; ++i)
    {
        if (x[i].hely < mini) mini = x[i].hely;
        else if (x[i].hely - mini > veg - kezd)
        {
            veg = x[i].hely;
            kezd = mini;
        }
    }

    if (veg - kezd == 0) cout << -1;
    else cout << kezd << " " << veg;

    return 0;
}
/*
5
4 3 5 1 2
*/
SubtaskSumTestVerdictTimeMemory
base50/50
1Accepted0/03ms1808 KiB
2Accepted0/020ms2768 KiB
3Accepted1/13ms2276 KiB
4Accepted2/23ms2620 KiB
5Accepted7/73ms2492 KiB
6Accepted2/224ms3316 KiB
7Accepted2/2207ms10156 KiB
8Accepted2/2246ms10164 KiB
9Accepted2/2247ms10416 KiB
10Accepted2/2244ms10792 KiB
11Accepted2/2244ms10972 KiB
12Accepted2/2239ms11056 KiB
13Accepted2/2259ms11272 KiB
14Accepted2/2244ms11220 KiB
15Accepted2/2207ms11480 KiB
16Accepted2/2250ms11632 KiB
17Accepted2/2245ms11620 KiB
18Accepted2/2243ms11652 KiB
19Accepted3/3204ms11648 KiB
20Accepted3/3211ms11648 KiB
21Accepted2/2208ms11620 KiB
22Accepted2/2244ms11872 KiB
23Accepted2/2244ms12104 KiB
24Accepted2/2196ms12044 KiB