81852024-01-12 16:24:30szabelrSípálya (55 pont)cpp17Wrong answer 18/55500ms5472 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 maxi = 0;
    for (int i = 0; i < K; i++)
        if (h[i]+i > h[maxi]+maxi) maxi = i;
    int m = h[maxi] - (K-1-maxi); // utolso lepcsofok magassaga
    int hs = 0;
    for (int i = 0; i < K; i++) hs += h[i];

    int minp = K * (K-1) / 2 + K * m - hs;

    for (int s = 1; s < N-K+1; s++) {
        /* int p = epit(h, s, K, N); */

        maxi = 0;
        for (int i = 0; i < K; i++)
            if (h[s+i]+i > h[s+maxi]+maxi) maxi = i;
        m = h[s+maxi] - (K-1-maxi); // utolso lepcsofok magassaga
        hs = hs-h[s-1]+h[s+K-1];
        //for (int i = 0; i < K; i++) hs += h[s+i];

        int p = K * (K-1) / 2 + K * m - hs;
        if (p < minp) minp = p;
    }
    cout << minp;
}
SubtaskSumTestVerdictTimeMemory
base18/55
1Accepted0/04ms3700 KiB
2Accepted0/03ms3932 KiB
3Accepted2/24ms3952 KiB
4Accepted2/24ms4148 KiB
5Accepted2/24ms4380 KiB
6Accepted2/24ms4332 KiB
7Wrong answer0/34ms4352 KiB
8Accepted1/112ms4544 KiB
9Accepted1/113ms4756 KiB
10Accepted1/114ms4968 KiB
11Accepted1/118ms5052 KiB
12Accepted1/118ms5176 KiB
13Accepted1/137ms5392 KiB
14Accepted2/241ms5372 KiB
15Accepted2/219ms5472 KiB
16Time limit exceeded0/2500ms3748 KiB
17Time limit exceeded0/2458ms3920 KiB
18Time limit exceeded0/2458ms3868 KiB
19Time limit exceeded0/3474ms3816 KiB
20Time limit exceeded0/2451ms3812 KiB
21Time limit exceeded0/2467ms3940 KiB
22Time limit exceeded0/2477ms4052 KiB
23Time limit exceeded0/2451ms4076 KiB
24Time limit exceeded0/2465ms4004 KiB
25Time limit exceeded0/2455ms4124 KiB
26Time limit exceeded0/2453ms4076 KiB
27Time limit exceeded0/2462ms4192 KiB
28Time limit exceeded0/3449ms4392 KiB
29Time limit exceeded0/3462ms4376 KiB
30Time limit exceeded0/3462ms4136 KiB