81252024-01-12 14:09:01TuruTamasFasor (40)cpp17Wrong answer 34/4081ms14352 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/03ms1844 KiB
2Accepted0/03ms2104 KiB
3Accepted2/23ms2216 KiB
4Wrong answer0/23ms2424 KiB
5Accepted2/23ms2644 KiB
6Accepted2/23ms3008 KiB
7Accepted2/23ms2976 KiB
8Accepted2/23ms2980 KiB
9Accepted2/23ms3040 KiB
10Accepted2/23ms3144 KiB
11Accepted2/23ms3532 KiB
12Accepted2/23ms3600 KiB
13Accepted2/261ms8120 KiB
14Wrong answer0/257ms13992 KiB
15Accepted2/272ms13544 KiB
16Accepted2/257ms8948 KiB
17Accepted2/272ms8956 KiB
18Accepted2/257ms8576 KiB
19Accepted2/259ms8452 KiB
20Wrong answer0/232ms9304 KiB
21Accepted2/281ms14352 KiB
22Accepted2/257ms9364 KiB