66542023-12-15 12:59:51Huni136Fasor (40)cpp17Time limit exceeded 8/40300ms5564 KiB
#include <iostream>
#include <vector>
using namespace std;

int main()
{
    int n,k;
    cin>>n>>k;
    vector<int> mag(n),bal(n),jobb(n);
    cin>>mag[0];
   // mag[-1]=1e9;
    bal[0]=n+3;
   // mag[n]=1e9;
    int ind;
    for(int i=1;i<n;i++)
    {
        cin>>mag[i];
        if(mag[i-1]>=mag[i])
        {
            bal[i]=i-1;
        }
        else
        {   ind=bal[i-1];
            while (ind!=-1 && mag[ind]<=mag[i])
            {
                ind=bal[ind];
            }
            
            bal[i]=ind;
        }
    }
    jobb[n-1]=-1;

    for(int i=n-2;i>=0;i--)
    {
        if(mag[i]<mag[i+1])
        {
            jobb[i]=i+1;
        }
        else
        {
            ind=jobb[i+1];
            while (ind!=-1 && mag[ind]<=mag[i])
            {
                ind=jobb[ind];
            }
            jobb[i]=ind;
        }
    }

    // for(auto it: bal)
    // {
    //     cout<<it+1<<" ";
    // }

    // cout<<endl;

    // for(auto it: jobb)
    // {
    //     cout<<it+1<<" ";
    // }

    for(int i=0;i<n;i++)
    {
        if((bal[i]+1)*(jobb[i]+1)==0)
        {
            if(abs(max(bal[i],jobb[i])-i)>k)
            {
               //cout<<"fasz";
                cout<<i+1;
                return 0;
            }
        }else if(i-bal[i]<k && jobb[i]-i>k)
        {
            cout<<i+1;
            return 0;
        }
    }
    cout<<-1;

    return 0;
}
SubtaskSumTestVerdictTimeMemory
base8/40
1Time limit exceeded0/0275ms1784 KiB
2Time limit exceeded0/0286ms2276 KiB
3Accepted2/23ms2272 KiB
4Accepted2/23ms2464 KiB
5Accepted2/23ms2680 KiB
6Time limit exceeded0/2250ms2044 KiB
7Time limit exceeded0/2266ms2860 KiB
8Time limit exceeded0/2266ms3240 KiB
9Accepted2/26ms3608 KiB
10Time limit exceeded0/2300ms3540 KiB
11Time limit exceeded0/2277ms3608 KiB
12Time limit exceeded0/2254ms3548 KiB
13Time limit exceeded0/2266ms3908 KiB
14Time limit exceeded0/2277ms3964 KiB
15Time limit exceeded0/2257ms5160 KiB
16Time limit exceeded0/2259ms5196 KiB
17Time limit exceeded0/2270ms5176 KiB
18Time limit exceeded0/2270ms5044 KiB
19Time limit exceeded0/2261ms5112 KiB
20Time limit exceeded0/2243ms4416 KiB
21Time limit exceeded0/2254ms5564 KiB
22Time limit exceeded0/2277ms5504 KiB