1581 2022. 11. 28 10:14:08 zsebi Fasor (40) cpp11 Elfogadva 40/40 108ms 19820 KiB
// fasor.cpp : This file contains the 'main' function. Program execution begins and ends there.
//

#include <iostream>
#include <queue>
#include <algorithm>

#define ll long long
using namespace std;

ll n, i;
vector<ll>st, x;
void build(ll p, ll l, ll r)
{
    if (l == r)
    {
        st[p] = x[l];
        return;
    }
    ll k = (l + r) / 2;
    build(2 * p, l, k);
    build(2 * p + 1, k + 1, r);
    st[p] = max(st[2 * p], st[2 * p + 1]);
}
ll leker(ll p, ll l, ll r, ll a, ll b)
{
    if (a <= l && r <= b)
    {
        return st[p];
    }
    if (r < a || b < l)return 0;
    ll k = (l + r) / 2;
   return max(leker(2 * p, l, k, a, b), leker(2 * p + 1, k + 1, r, a, b));
}
ll k;
int main()
{
    cin >> n >> k;
    x.resize(n + 1);
    st.resize(4 * n + 1);
    for (int i = 1; i <= n; ++i)
        cin >> x[i];
    build(1, 1, n);
    ll maxi = 0;
    //for (auto& e : st)cout << e << " ";
    //cout << "\n";
    for (int i = 1; i <= k; ++i)
    {
        maxi = max(maxi, x[i]);
        if (leker(1, 1, n, i, i + k) <= x[i]&& maxi <= x[i])
        {
            cout << i;
            return 0;
        }
    }
    for (int i = k + 1; i <= n; ++i)
    {
        if (leker(1, 1, n, i - k, i + k) <= x[i])
        {
            cout << i;
            return 0;
        }
    }
    cout << "-1";
    return  0;
}

// Run program: Ctrl + F5 or Debug > Start Without Debugging menu
// Debug program: F5 or Debug > Start Debugging menu

// Tips for Getting Started: 
//   1. Use the Solution Explorer window to add/manage files
//   2. Use the Team Explorer window to connect to source control
//   3. Use the Output window to see build output and other messages
//   4. Use the Error List window to view errors
//   5. Go to Project > Add New Item to create new code files, or Project > Add Existing Item to add existing code files to the project
//   6. In the future, to open this project again, go to File > Open > Project and select the .sln file
Részfeladat Összpont Teszt Verdikt Idő Memória
base 40/40
1 Elfogadva 0/0 3ms 1872 KiB
2 Elfogadva 0/0 4ms 2828 KiB
3 Elfogadva 2/2 2ms 2168 KiB
4 Elfogadva 2/2 2ms 2376 KiB
5 Elfogadva 2/2 2ms 2580 KiB
6 Elfogadva 2/2 2ms 2780 KiB
7 Elfogadva 2/2 2ms 3020 KiB
8 Elfogadva 2/2 3ms 3392 KiB
9 Elfogadva 2/2 4ms 4188 KiB
10 Elfogadva 2/2 6ms 4264 KiB
11 Elfogadva 2/2 6ms 4264 KiB
12 Elfogadva 2/2 4ms 4264 KiB
13 Elfogadva 2/2 64ms 11412 KiB
14 Elfogadva 2/2 59ms 11592 KiB
15 Elfogadva 2/2 86ms 19468 KiB
16 Elfogadva 2/2 87ms 19596 KiB
17 Elfogadva 2/2 92ms 19604 KiB
18 Elfogadva 2/2 97ms 19604 KiB
19 Elfogadva 2/2 108ms 19728 KiB
20 Elfogadva 2/2 43ms 11876 KiB
21 Elfogadva 2/2 90ms 19820 KiB
22 Elfogadva 2/2 93ms 19800 KiB