81802024-01-12 16:00:55szabelrSípálya (55 pont)cpp17Wrong answer 18/55481ms6988 KiB
#include <iostream>

using namespace std;

long epit(long h[], int s, int K, int N) {
    int maxi = 0;
    for (int i = 0; i < K; i++)
        if (h[s + i] + i > h[s + maxi] + maxi) maxi = i;
    /* cout << "maxi = " << maxi << endl; */

    int m = h[s + maxi] - (K - 1 - maxi); // utolso lepcsofok magassaga
    /* cout << "m = " << m << endl; */

    int hs = 0;
    for (int i = 0; i < K; i++) hs += h[s + i];

    return K * (K - 1) / 2 + K * m - hs;
}

int main() {

    long  N, K, h[200000];

    cin >> N >> K;
    for (int i = 0; i < N; i++) cin >> h[i];

    int minp = epit(h, 0, K, N);
    for (int i = 1; i <= N - K; i++) {
        int p = epit(h, i, K, N);
        if (p < minp) minp = p;
    }
    cout << minp;
}
SubtaskSumTestVerdictTimeMemory
base18/55
1Accepted0/04ms4968 KiB
2Accepted0/04ms5164 KiB
3Accepted2/24ms5372 KiB
4Accepted2/24ms5740 KiB
5Accepted2/24ms5712 KiB
6Accepted2/24ms5788 KiB
7Wrong answer0/34ms5768 KiB
8Accepted1/117ms5968 KiB
9Accepted1/119ms6184 KiB
10Accepted1/120ms6392 KiB
11Accepted1/129ms6600 KiB
12Accepted1/128ms6688 KiB
13Accepted1/161ms6948 KiB
14Accepted2/268ms6836 KiB
15Accepted2/229ms6988 KiB
16Time limit exceeded0/2481ms4548 KiB
17Time limit exceeded0/2442ms4428 KiB
18Time limit exceeded0/2467ms4628 KiB
19Time limit exceeded0/3458ms4728 KiB
20Time limit exceeded0/2449ms4828 KiB
21Time limit exceeded0/2469ms4800 KiB
22Time limit exceeded0/2481ms4708 KiB
23Time limit exceeded0/2453ms4824 KiB
24Time limit exceeded0/2462ms4900 KiB
25Time limit exceeded0/2462ms5136 KiB
26Time limit exceeded0/2469ms5172 KiB
27Time limit exceeded0/2449ms5132 KiB
28Time limit exceeded0/3455ms5276 KiB
29Time limit exceeded0/3469ms5304 KiB
30Time limit exceeded0/3460ms5532 KiB