72262024-01-03 19:28:38MagyarKendeSZLGFasor (40)cpp17Elfogadva 40/4028ms7000 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);

    if (N <= K + 1) {
        cout << max_element(all(v)) - v.begin() + 1;
        exit(0);
    }

    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;
}
RészfeladatÖsszpontTesztVerdiktIdőMemória
base40/40
1Elfogadva0/03ms1976 KiB
2Elfogadva0/04ms2072 KiB
3Elfogadva2/23ms2196 KiB
4Elfogadva2/23ms2444 KiB
5Elfogadva2/22ms2504 KiB
6Elfogadva2/23ms2620 KiB
7Elfogadva2/23ms2864 KiB
8Elfogadva2/23ms3004 KiB
9Elfogadva2/24ms3092 KiB
10Elfogadva2/24ms3408 KiB
11Elfogadva2/24ms3364 KiB
12Elfogadva2/23ms3624 KiB
13Elfogadva2/216ms4732 KiB
14Elfogadva2/214ms4516 KiB
15Elfogadva2/224ms6548 KiB
16Elfogadva2/226ms6244 KiB
17Elfogadva2/228ms6588 KiB
18Elfogadva2/228ms5796 KiB
19Elfogadva2/228ms5604 KiB
20Elfogadva2/212ms5508 KiB
21Elfogadva2/226ms7000 KiB
22Elfogadva2/228ms5860 KiB