70922023-12-30 11:05:441478Fasor (40)cpp17Elfogadva 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;
}
RészfeladatÖsszpontTesztVerdiktIdőMemória
base40/40
1Elfogadva0/03ms1812 KiB
2Elfogadva0/06ms2228 KiB
3Elfogadva2/23ms2272 KiB
4Elfogadva2/23ms2328 KiB
5Elfogadva2/23ms2404 KiB
6Elfogadva2/23ms2400 KiB
7Elfogadva2/23ms2408 KiB
8Elfogadva2/23ms2416 KiB
9Elfogadva2/26ms2700 KiB
10Elfogadva2/26ms2660 KiB
11Elfogadva2/26ms2912 KiB
12Elfogadva2/24ms2868 KiB
13Elfogadva2/267ms8600 KiB
14Elfogadva2/264ms12840 KiB
15Elfogadva2/298ms17004 KiB
16Elfogadva2/297ms13760 KiB
17Elfogadva2/2111ms15700 KiB
18Elfogadva2/2104ms11268 KiB
19Elfogadva2/2100ms6692 KiB
20Elfogadva2/250ms13432 KiB
21Elfogadva2/2104ms19168 KiB
22Elfogadva2/2112ms13260 KiB