81262024-01-12 14:09:30TuruTamasFasor (40)cpp17Wrong answer 34/4081ms12940 KiB
#include <bits/stdc++.h>
using namespace std;

#ifdef DEBUG
ifstream in_file("minta/be1.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();
        while (pq.top().second <= n-2*K || pq.top().first <= ki) {
            pq.pop();
            if (pq.size() == 0) {
                cout << n-K+1 << "\n";
                exit(0);
            }
        }
    }
}
SubtaskSumTestVerdictTimeMemory
base34/40
1Accepted0/03ms1936 KiB
2Accepted0/03ms2200 KiB
3Accepted2/22ms2276 KiB
4Wrong answer0/23ms2396 KiB
5Accepted2/23ms2404 KiB
6Accepted2/23ms2564 KiB
7Accepted2/22ms2656 KiB
8Accepted2/23ms2660 KiB
9Accepted2/23ms2652 KiB
10Accepted2/23ms2788 KiB
11Accepted2/23ms2872 KiB
12Accepted2/23ms2972 KiB
13Accepted2/261ms7180 KiB
14Wrong answer0/256ms12940 KiB
15Accepted2/272ms12548 KiB
16Accepted2/256ms8120 KiB
17Accepted2/271ms8180 KiB
18Accepted2/257ms7660 KiB
19Accepted2/259ms7380 KiB
20Wrong answer0/232ms8200 KiB
21Accepted2/281ms12840 KiB
22Accepted2/257ms8304 KiB