70922023-12-30 11:05:441478Fasor (40)cpp17Accepted 40/40112ms19168 KiB
#include <bits/stdc++.h>  
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int,int> p32;
typedef pair<ll,ll> p64;
typedef pair<double,double> pdd;
typedef vector<ll> v64;
typedef vector<int> v32;
typedef vector<vector<int> > vv32;
typedef vector<vector<ll> > vv64;
typedef vector<vector<p64> > vvp64;
typedef vector<p64> vp64;
typedef vector<p32> vp32;
ll MOD = 998244353;
double eps = 1e-12;
#define forn(i,e) for(ll i = 0; i < e; i++)
#define forsn(i,s,e) for(ll i = s; i < e; i++)
#define rforn(i,s) for(ll i = s; i >= 0; i--)
#define rforsn(i,s,e) for(ll i = s; i >= e; i--)
#define ln "\n"
#define dbg(x) cout<<#x<<" = "<<x<<ln
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define INF 2e18
#define all(x) (x).begin(), (x).end()
#define sz(x) ((ll)(x).size())
 
int main()
{
    //ifstream cin("in.txt");
    int n, k;
    cin >> n >> k;
    vector<int> a(n + 1);
    for(int i = 1; i <= n; i++){
        cin >> a[i];
    }

    set<pair<int, int>> s;
    for(int i = 1; i <= k + 1 && i <= n; i++){
        s.insert({a[i], i});
    }

    int i = 1;
    bool ansFound = false;

    while(i <= n && !ansFound){
        if(a[i] == s.crbegin() -> first){
            cout << i;
            ansFound = true;
        }
        else{
            if(i - k >= 1){
                s.erase({a[i - k], i - k});
            }
            if(i + k + 1 <= n){
                s.insert({a[i + k + 1], i + k + 1});
            }
        }
        i++;
    }

    if(!ansFound) cout << -1;
}
SubtaskSumTestVerdictTimeMemory
base40/40
1Accepted0/03ms1812 KiB
2Accepted0/06ms2228 KiB
3Accepted2/23ms2272 KiB
4Accepted2/23ms2328 KiB
5Accepted2/23ms2404 KiB
6Accepted2/23ms2400 KiB
7Accepted2/23ms2408 KiB
8Accepted2/23ms2416 KiB
9Accepted2/26ms2700 KiB
10Accepted2/26ms2660 KiB
11Accepted2/26ms2912 KiB
12Accepted2/24ms2868 KiB
13Accepted2/267ms8600 KiB
14Accepted2/264ms12840 KiB
15Accepted2/298ms17004 KiB
16Accepted2/297ms13760 KiB
17Accepted2/2111ms15700 KiB
18Accepted2/2104ms11268 KiB
19Accepted2/2100ms6692 KiB
20Accepted2/250ms13432 KiB
21Accepted2/2104ms19168 KiB
22Accepted2/2112ms13260 KiB