81212024-01-12 14:04:24TuruTamasFasor (40)cpp17Wrong answer 34/4075ms14280 KiB
#include <bits/stdc++.h>
using namespace std;

#ifdef DEBUG
ifstream in_file("minta/be2.txt");
#define input in_file
#define INTHENAMEOFGOD
#else
#define input cin
#define INTHENAMEOFGOD \
    ios::sync_with_stdio(0); \
    cin.tie(0); \
    cout.tie(0);
#endif
typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef pair<ll, ll> pii;

ll N, K, a;
queue<ll> q;
priority_queue<pii> pq;

int main() {
    input >> N >> K;
    for (ll k = 0; k < K; k++) {
        input >> a;
        q.push(a);
        pq.emplace(a, k);
    }
    for (ll n = K; n < N; n++) {
        input >> a;
        pq.emplace(a, n);
        q.push(a);
        ll ki = q.front();
        q.pop();
        ll fa = n-K;
        while (pq.top().second <= n-K || pq.top().first <= ki) {
            pq.pop();
            if (pq.size() == 0) {
                cout << n-K+1 << "\n";
                exit(0);
            }
        }
    }
}
SubtaskSumTestVerdictTimeMemory
base34/40
1Accepted0/03ms1844 KiB
2Accepted0/03ms2012 KiB
3Accepted2/23ms2360 KiB
4Wrong answer0/23ms2576 KiB
5Accepted2/23ms2600 KiB
6Accepted2/23ms2784 KiB
7Accepted2/23ms2916 KiB
8Accepted2/23ms2900 KiB
9Accepted2/23ms3088 KiB
10Accepted2/23ms3332 KiB
11Accepted2/23ms3552 KiB
12Accepted2/23ms3656 KiB
13Accepted2/254ms8188 KiB
14Wrong answer0/250ms14280 KiB
15Accepted2/267ms13408 KiB
16Accepted2/252ms8876 KiB
17Accepted2/265ms8968 KiB
18Accepted2/252ms8444 KiB
19Accepted2/254ms8076 KiB
20Wrong answer0/229ms8780 KiB
21Accepted2/275ms13572 KiB
22Accepted2/252ms8736 KiB