72252024-01-03 19:25:13MagyarKendeSZLGFasor (40)cpp17Runtime error 38/4027ms7004 KiB
#include <bits/stdc++.h>

#define speed cin.tie(0); ios::sync_with_stdio(0)
#define cinv(v) for (auto& e : v) cin >> e;
#define all(v) v.begin(), v.end()
#define has(s, e) s.count(e)

using namespace std;
using ll = long long;
using point = array<int, 2>;

int main() {
    speed;

    int N, K;
    cin >> N >> K;
    vector<int> v(N);
    cinv(v);

    deque<point> q;
    
    for (int i = 0; i < K + 1; i++) {

        while (!q.empty() && q.back()[0] < v[i]) {
            q.pop_back();
        }

        q.push_back({v[i], i});
    }

    if (q.front()[0] == v[0]) {
        cout << 1;
        exit(0);
    }

    int bagoly = 1, left = 1 - K, right = 1 + K;

    while (bagoly < N) {

        if (!q.empty() && q.front()[1] < left) {
            q.pop_front();
        }

        if (right < N) {
            while (!q.empty() && q.back()[0] < v[right]) {
                q.pop_back();
            }

            q.push_back({v[right], right});
        }

        if (!q.empty() && q.front()[0] == v[bagoly]) {
            cout << bagoly + 1;
            exit(0);
        }

        left++;
        bagoly++;
        right++;
    }

    cout << -1;
}
SubtaskSumTestVerdictTimeMemory
base38/40
1Accepted0/03ms1832 KiB
2Accepted0/04ms2216 KiB
3Accepted2/23ms2516 KiB
4Accepted2/23ms2560 KiB
5Accepted2/23ms2772 KiB
6Accepted2/23ms2804 KiB
7Accepted2/23ms2896 KiB
8Accepted2/23ms3024 KiB
9Accepted2/23ms3148 KiB
10Accepted2/24ms3148 KiB
11Accepted2/24ms3400 KiB
12Accepted2/24ms3612 KiB
13Accepted2/214ms4776 KiB
14Runtime error0/214ms5464 KiB
15Accepted2/224ms6448 KiB
16Accepted2/225ms6272 KiB
17Accepted2/227ms6836 KiB
18Accepted2/227ms6036 KiB
19Accepted2/227ms5600 KiB
20Accepted2/212ms5388 KiB
21Accepted2/224ms7004 KiB
22Accepted2/227ms5464 KiB