15312022-11-22 12:28:54TomaSajtFasor (40)cpp14Accepted 40/4028ms8868 KiB
#include <bits/stdc++.h>
#define speed ios::sync_with_stdio(0);cin.tie(0)
using namespace std;

int main() {
    speed;
    int n, k;
    cin >> n >> k;
    int l = 2 * k + 1;
    int m = n + 2 * k;
    vector<int> v(m, INT_MIN);
    for (int i = k; i < n + k; i++) cin >> v[i];
    deque<int> dq;
    vector<int> res(m - l + 1);
    for (int i = 0; i < m; i++) {
        while (!dq.empty() && i - dq.front() >= l) dq.pop_front();
        while (!dq.empty() && v[dq.back()] <= v[i]) dq.pop_back();
        dq.push_back(i);
        if (i - l + 1 >= 0) res[i - l + 1] = v[dq.front()];
    }
    for (int i = 0; i < n; i++) {
        if (v[i + k] >= res[i]) {
            cout << i + 1;
            return 0;
        }
    }
    cout << "-1";
}
SubtaskSumTestVerdictTimeMemory
base40/40
1Accepted0/03ms1828 KiB
2Accepted0/03ms2228 KiB
3Accepted2/22ms2224 KiB
4Accepted2/22ms2424 KiB
5Accepted2/22ms2632 KiB
6Accepted2/22ms2980 KiB
7Accepted2/22ms3060 KiB
8Accepted2/22ms3152 KiB
9Accepted2/23ms3472 KiB
10Accepted2/23ms3424 KiB
11Accepted2/23ms3828 KiB
12Accepted2/23ms3752 KiB
13Accepted2/214ms5604 KiB
14Accepted2/217ms8260 KiB
15Accepted2/223ms8384 KiB
16Accepted2/225ms7944 KiB
17Accepted2/227ms8592 KiB
18Accepted2/226ms7648 KiB
19Accepted2/225ms7240 KiB
20Accepted2/210ms6692 KiB
21Accepted2/224ms8868 KiB
22Accepted2/228ms8124 KiB