241372026-02-04 18:13:17Pedri26Legmesszebbi rossz sorrendű (35 pont)cpp17Accepted 35/3524ms1220 KiB
#include <bits/stdc++.h>

using namespace std;
int n;

struct bencu
{
    int szam;
    int poz;
} a[100001];

bool valami(const bencu x, const bencu y)
{
    return (x.szam<y.szam);
}

int main() {
	
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i].szam;
        a[i].poz=i;
    }

    sort(a+1, a+n+1, valami);
    /*for(int i=1;i<=n;i++)
    {
        cout<<a[i].szam<<" ";
    }
    cout<<endl;
    for(int i=1;i<=n;i++)
    {
        cout<<a[i].poz<<" ";
    }
    cout<<endl;*/
    int lns=-1, poz1=-1, poz2=-1;
    int maxind=0, maxindpoz=0;
    a[0].szam=INT_MIN;
    for(int i=1;i<=n;i++)
    {
        if(a[i].poz<maxind && a[i].szam>a[maxindpoz].szam)
        {
            //cout<<maxind-a[i].poz<<endl;
            if(maxind-a[i].poz>lns)
            {
                lns=maxind-a[i].poz;
                poz1=a[i].poz;
                poz2=maxind;
            }
        }
        if(a[i].poz>maxind)
        {
            maxind=a[i].poz;
            maxindpoz=i;
        }
    }
    if(lns>0)cout<<poz1<<" "<<poz2;
    else cout<<"-1";

    
    return 0;
}
SubtaskSumTestVerdictTimeMemory
base35/35
1Accepted0/01ms316 KiB
2Accepted0/024ms1076 KiB
3Accepted1/11ms500 KiB
4Accepted1/11ms316 KiB
5Accepted1/11ms316 KiB
6Accepted1/11ms316 KiB
7Accepted1/11ms500 KiB
8Accepted1/11ms508 KiB
9Accepted1/11ms316 KiB
10Accepted1/12ms508 KiB
11Accepted1/12ms316 KiB
12Accepted2/28ms700 KiB
13Accepted2/29ms788 KiB
14Accepted2/29ms808 KiB
15Accepted2/27ms660 KiB
16Accepted2/210ms820 KiB
17Accepted2/217ms820 KiB
18Accepted2/218ms952 KiB
19Accepted2/220ms1076 KiB
20Accepted2/221ms984 KiB
21Accepted2/224ms1156 KiB
22Accepted2/224ms1208 KiB
23Accepted2/217ms980 KiB
24Accepted2/217ms1220 KiB