81722024-01-12 15:41:51szabelrSípálya (55 pont)cpp17Wrong answer 18/55500ms4796 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, 1, 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/03ms3424 KiB
2Accepted0/03ms3652 KiB
3Accepted2/24ms3864 KiB
4Accepted2/24ms4072 KiB
5Accepted2/24ms4248 KiB
6Accepted2/24ms4332 KiB
7Wrong answer0/34ms4432 KiB
8Accepted1/116ms4436 KiB
9Accepted1/118ms4560 KiB
10Accepted1/119ms4644 KiB
11Accepted1/128ms4644 KiB
12Accepted1/128ms4640 KiB
13Accepted1/157ms4648 KiB
14Accepted2/265ms4796 KiB
15Accepted2/228ms4756 KiB
16Time limit exceeded0/2500ms3016 KiB
17Time limit exceeded0/2462ms3160 KiB
18Time limit exceeded0/2465ms3236 KiB
19Time limit exceeded0/3470ms3428 KiB
20Time limit exceeded0/2462ms3664 KiB
21Time limit exceeded0/2465ms3900 KiB
22Time limit exceeded0/2453ms3856 KiB
23Time limit exceeded0/2469ms3948 KiB
24Time limit exceeded0/2433ms3928 KiB
25Time limit exceeded0/2462ms3916 KiB
26Time limit exceeded0/2474ms3940 KiB
27Time limit exceeded0/2458ms4120 KiB
28Time limit exceeded0/3437ms4296 KiB
29Time limit exceeded0/3462ms4440 KiB
30Time limit exceeded0/3446ms4392 KiB