81912024-01-12 17:42:17MagyarKendeSZLGSípálya (55 pont)cpp17Time limit exceeded 21/55479ms5940 KiB
#include <iostream>
#include <vector>
#include <deque>
#include <climits>
using namespace std;

using ll = unsigned long long;
#define speed cin.tie(0); ios::sync_with_stdio(0)

vector<ll> heightS;
int N, K;

int main() {
    speed;

    cin >> N >> K;

    heightS.resize(N);

    for (int i = 0; i < N; i++) {
        cin >> heightS[i];
        heightS[i] += i;
    }

    deque<pair<int, int>> q;
    vector<ll> v(N - K + 1);
    
    for (int right = 0; right < K; right++) {
        while (!q.empty() && q.back().first < heightS[right]) q.pop_back();
        q.push_back({heightS[right], right});
    }

    v[0] = q.front().first;
    int p = 0;

    int left = 1, right = K;
    while (left < N - K + 1) {
        while (!q.empty() && q.front().second < left) q.pop_front();

        while (!q.empty() && q.back().first < heightS[right]) q.pop_back();

        q.push_back({heightS[right], right});

        left++;
        right++;

        v[++p] = q.front().first;
    }
    
    ll result = ULLONG_MAX;

    for (int i = 0; i < N - K; i++) {
        ll curr = 0;
        for (int j = i; j < i + K; j++) {

            curr += v[i] - heightS[j];
        }
        result = min(result, curr);
    }

    cout << result;
}
SubtaskSumTestVerdictTimeMemory
base21/55
1Accepted0/03ms1824 KiB
2Accepted0/03ms2016 KiB
3Accepted2/23ms2248 KiB
4Accepted2/23ms2460 KiB
5Accepted2/23ms2436 KiB
6Accepted2/23ms2432 KiB
7Accepted3/33ms2556 KiB
8Accepted1/17ms2908 KiB
9Accepted1/18ms2988 KiB
10Accepted1/18ms2916 KiB
11Accepted1/110ms2928 KiB
12Accepted1/110ms3068 KiB
13Accepted1/119ms3140 KiB
14Accepted2/221ms3136 KiB
15Accepted2/210ms3464 KiB
16Time limit exceeded0/2476ms5768 KiB
17Time limit exceeded0/2474ms5032 KiB
18Time limit exceeded0/2455ms4856 KiB
19Time limit exceeded0/3470ms4520 KiB
20Time limit exceeded0/2470ms5708 KiB
21Time limit exceeded0/2467ms5716 KiB
22Time limit exceeded0/2467ms5684 KiB
23Time limit exceeded0/2479ms5684 KiB
24Time limit exceeded0/2479ms5940 KiB
25Time limit exceeded0/2467ms5828 KiB
26Time limit exceeded0/2470ms5756 KiB
27Time limit exceeded0/2462ms5628 KiB
28Time limit exceeded0/3467ms5744 KiB
29Time limit exceeded0/3470ms5808 KiB
30Time limit exceeded0/3465ms5848 KiB