70912023-12-30 11:04:091478Fasor (40)cpp17Runtime error 38/40116ms19740 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++){
        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++;
    }
}
SubtaskSumTestVerdictTimeMemory
base38/40
1Accepted0/03ms1812 KiB
2Accepted0/06ms2184 KiB
3Accepted2/23ms2220 KiB
4Accepted2/23ms2460 KiB
5Accepted2/23ms2712 KiB
6Accepted2/23ms2920 KiB
7Accepted2/23ms3144 KiB
8Accepted2/23ms3216 KiB
9Accepted2/24ms3224 KiB
10Accepted2/26ms3188 KiB
11Accepted2/26ms3520 KiB
12Accepted2/24ms3400 KiB
13Accepted2/264ms9124 KiB
14Runtime error0/259ms13752 KiB
15Accepted2/297ms17676 KiB
16Accepted2/293ms14360 KiB
17Accepted2/2104ms16224 KiB
18Accepted2/298ms11892 KiB
19Accepted2/294ms7332 KiB
20Accepted2/250ms14144 KiB
21Accepted2/2104ms19740 KiB
22Accepted2/2116ms13868 KiB