236132026-01-26 10:24:40sarminFasor (40)cpp17Accepted 40/4061ms6164 KiB
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
// const ll MOD = 1e9+7;

#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int n,k; cin >> n >> k;
    vector<int> bal(n), jobb(n), a(n);
    priority_queue<pair<int, int>> q;
    for (int i = 0; i < n; i++) {
    	cin >> a[i];
    	q.push({a[i], i});
    	while (i-q.top().second > k) q.pop();
    	bal[i] = q.top().first;
    }
    
    q = priority_queue<pair<int, int>>();
    for (int i = n-1; i >= 0; i--) {
    	q.push({a[i], i});
    	while (q.top().second-i > k) q.pop();
    	jobb[i] = q.top().first;
    }
    
    for (int i = 0; i < n; i++) {
    	if (bal[i] <= a[i] && jobb[i] <= a[i]) {
    		cout << i+1 << "\n"; return 0;
    	}
    }
    cout << "-1\n";

    return 0;
}
SubtaskSumTestVerdictTimeMemory
base40/40
1Accepted0/01ms316 KiB
2Accepted0/03ms836 KiB
3Accepted2/21ms316 KiB
4Accepted2/21ms316 KiB
5Accepted2/21ms316 KiB
6Accepted2/21ms316 KiB
7Accepted2/21ms316 KiB
8Accepted2/21ms316 KiB
9Accepted2/23ms564 KiB
10Accepted2/23ms924 KiB
11Accepted2/24ms644 KiB
12Accepted2/23ms732 KiB
13Accepted2/228ms2724 KiB
14Accepted2/221ms3388 KiB
15Accepted2/250ms4880 KiB
16Accepted2/254ms4824 KiB
17Accepted2/254ms4780 KiB
18Accepted2/259ms4776 KiB
19Accepted2/261ms4940 KiB
20Accepted2/223ms2572 KiB
21Accepted2/250ms4780 KiB
22Accepted2/243ms6164 KiB