81892024-01-12 16:53:01MagyarKendeSZLGSípálya (55 pont)cpp17Time limit exceeded 21/55486ms5392 KiB
#include <iostream>
#include <vector>
#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;

ll window(int i) {
    ll cost = 0, mx = 0;

    for (int j = i; j < i + K; j++) {
        mx = max(mx, heightS[j]);
    }

    for (int j = i; j < i + K; j++) {
        cost += mx - heightS[j];
    }

    return cost;
}

int main() {
    speed;

    cin >> N >> K;

    heightS.resize(N);

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

    ll result = LLONG_MAX;

    for (int i = 0; i <= N - K; i++) {
        result = min(result, window(i));
    }

    cout << result;
}
SubtaskSumTestVerdictTimeMemory
base21/55
1Accepted0/03ms1888 KiB
2Accepted0/03ms2084 KiB
3Accepted2/23ms2180 KiB
4Accepted2/23ms2304 KiB
5Accepted2/23ms2516 KiB
6Accepted2/23ms2600 KiB
7Accepted3/33ms2744 KiB
8Accepted1/19ms3024 KiB
9Accepted1/112ms3256 KiB
10Accepted1/113ms3208 KiB
11Accepted1/118ms3460 KiB
12Accepted1/118ms3412 KiB
13Accepted1/139ms3412 KiB
14Accepted2/245ms3668 KiB
15Accepted2/218ms3772 KiB
16Time limit exceeded0/2463ms4644 KiB
17Time limit exceeded0/2455ms4548 KiB
18Time limit exceeded0/2474ms4492 KiB
19Time limit exceeded0/3465ms4744 KiB
20Time limit exceeded0/2474ms4744 KiB
21Time limit exceeded0/2486ms4796 KiB
22Time limit exceeded0/2474ms5072 KiB
23Time limit exceeded0/2462ms4924 KiB
24Time limit exceeded0/2469ms4916 KiB
25Time limit exceeded0/2430ms4976 KiB
26Time limit exceeded0/2469ms5196 KiB
27Time limit exceeded0/2467ms5180 KiB
28Time limit exceeded0/3453ms5248 KiB
29Time limit exceeded0/3451ms5392 KiB
30Time limit exceeded0/3469ms5264 KiB