81572024-01-12 14:52:29TuruTamasFasor (40)cpp17Wrong answer 34/4057ms13776 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();
        while (pq.top().second < n-2*K) {
            pq.pop();
            if (pq.size() == 0) {
                cout << n-K+1 << "\n";
                exit(0);
            }
        }
        if ( pq.top().first <= ki) {
            cout << n-K+1 << "\n";
            exit(0);
        }
    }
}
SubtaskSumTestVerdictTimeMemory
base34/40
1Accepted0/03ms1812 KiB
2Accepted0/03ms2060 KiB
3Accepted2/23ms2244 KiB
4Wrong answer0/23ms2480 KiB
5Accepted2/23ms2540 KiB
6Accepted2/23ms2544 KiB
7Accepted2/23ms2572 KiB
8Accepted2/23ms2756 KiB
9Accepted2/23ms2960 KiB
10Accepted2/23ms3192 KiB
11Accepted2/23ms3384 KiB
12Accepted2/23ms3588 KiB
13Accepted2/245ms8020 KiB
14Wrong answer0/250ms13776 KiB
15Accepted2/250ms13132 KiB
16Accepted2/241ms8692 KiB
17Accepted2/252ms8636 KiB
18Accepted2/241ms8104 KiB
19Accepted2/241ms7828 KiB
20Wrong answer0/230ms8500 KiB
21Accepted2/257ms13448 KiB
22Accepted2/237ms8500 KiB