81792024-01-12 15:51:03szabelrSípálya (55 pont)cpp17Wrong answer 18/55479ms5520 KiB
#include <iostream>

using namespace std;

int epit(int 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() {

    int 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/04ms3696 KiB
2Accepted0/03ms3656 KiB
3Accepted2/24ms3868 KiB
4Accepted2/24ms4084 KiB
5Accepted2/24ms4444 KiB
6Accepted2/24ms4564 KiB
7Wrong answer0/34ms4796 KiB
8Accepted1/116ms4948 KiB
9Accepted1/117ms5204 KiB
10Accepted1/119ms5208 KiB
11Accepted1/128ms5288 KiB
12Accepted1/128ms5404 KiB
13Accepted1/159ms5376 KiB
14Accepted2/265ms5520 KiB
15Accepted2/228ms5516 KiB
16Time limit exceeded0/2472ms3956 KiB
17Time limit exceeded0/2479ms4016 KiB
18Time limit exceeded0/2477ms4220 KiB
19Time limit exceeded0/3462ms4312 KiB
20Time limit exceeded0/2477ms4196 KiB
21Time limit exceeded0/2446ms4140 KiB
22Time limit exceeded0/2453ms4212 KiB
23Time limit exceeded0/2446ms4260 KiB
24Time limit exceeded0/2458ms4308 KiB
25Time limit exceeded0/2465ms4396 KiB
26Time limit exceeded0/2472ms4392 KiB
27Time limit exceeded0/2465ms4320 KiB
28Time limit exceeded0/3465ms4804 KiB
29Time limit exceeded0/3460ms4812 KiB
30Time limit exceeded0/3465ms5076 KiB