66532023-12-15 12:49:53Huni136Fasor (40)cpp17Wrong answer 26/4079ms8772 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]=-1;
   // 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
base26/40
1Accepted0/03ms2092 KiB
2Accepted0/06ms2368 KiB
3Wrong answer0/23ms2256 KiB
4Accepted2/23ms2300 KiB
5Wrong answer0/22ms2300 KiB
6Accepted2/23ms2432 KiB
7Wrong answer0/23ms2688 KiB
8Accepted2/23ms2780 KiB
9Wrong answer0/24ms2956 KiB
10Accepted2/27ms3216 KiB
11Accepted2/26ms3168 KiB
12Wrong answer0/24ms3164 KiB
13Accepted2/239ms5316 KiB
14Wrong answer0/235ms5444 KiB
15Accepted2/263ms8120 KiB
16Accepted2/268ms7952 KiB
17Accepted2/275ms8208 KiB
18Accepted2/275ms8160 KiB
19Accepted2/278ms8164 KiB
20Wrong answer0/225ms6084 KiB
21Accepted2/263ms8504 KiB
22Accepted2/279ms8772 KiB