15302022-11-22 10:25:59kicsiboglarFasor (40)cpp11Accepted 40/4032ms13612 KiB
#include <iostream>
#include <vector>

#define ll long long
using namespace std;

//ifstream cin ("input.in");
//ofstream cout ("output.out");

ll n,m,i,j,a,b,k;

struct element
{
    ll value,big_left,big_right;
};

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);

    cin>>n>>k;
    vector <element> x(n+1);
    for (i=1;i<=n;++i)
    {
        cin>>x[i].value;
        if (i==1) continue;
        j=i-1;
        while (j!=0&&x[j].value<=x[i].value) j=x[j].big_left;
        x[i].big_left=j;
    }

    for (i=n-1;i>=1;--i)
    {
        j=i+1;
        while (j!=0&&x[j].value<=x[i].value) j=x[j].big_right;
        x[i].big_right=j;
    }
    for (i=1;i<=n;++i)
    {
        if (i-x[i].big_left>k||x[i].big_left==0)
        {
            if (x[i].big_right-i>k||x[i].big_right==0)
            {
                cout<<i;
                return 0;
            }
        }
    }
    cout<<"-1";
}
SubtaskSumTestVerdictTimeMemory
base40/40
1Accepted0/03ms1884 KiB
2Accepted0/03ms2208 KiB
3Accepted2/22ms2264 KiB
4Accepted2/22ms2368 KiB
5Accepted2/22ms2524 KiB
6Accepted2/22ms2732 KiB
7Accepted2/22ms3092 KiB
8Accepted2/22ms3180 KiB
9Accepted2/23ms3432 KiB
10Accepted2/24ms3560 KiB
11Accepted2/23ms3672 KiB
12Accepted2/23ms3748 KiB
13Accepted2/214ms8036 KiB
14Accepted2/214ms8264 KiB
15Accepted2/224ms13116 KiB
16Accepted2/225ms13052 KiB
17Accepted2/227ms13052 KiB
18Accepted2/227ms13460 KiB
19Accepted2/227ms13612 KiB
20Accepted2/212ms8836 KiB
21Accepted2/224ms13532 KiB
22Accepted2/232ms13528 KiB