81872024-01-12 16:41:59szabelrSípálya (55 pont)cpp17Wrong answer 18/55326ms5360 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); */

        if (maxi > 0) {
            if (h[s-1+maxi]+maxi-1 > h[s+K-1]+K-1) maxi--;
            else maxi = K-1;
        }
        else {
            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];
        int p = K * (K-1) / 2 + K * m - hs;
        if (p < minp) minp = p;
    }
    cout << minp;
}
SubtaskSumTestVerdictTimeMemory
base18/55
1Accepted0/03ms3424 KiB
2Accepted0/04ms3664 KiB
3Accepted2/24ms3856 KiB
4Accepted2/24ms4068 KiB
5Accepted2/24ms4288 KiB
6Accepted2/24ms4352 KiB
7Wrong answer0/34ms4332 KiB
8Accepted1/17ms4332 KiB
9Accepted1/17ms4480 KiB
10Accepted1/17ms4744 KiB
11Accepted1/114ms4624 KiB
12Accepted1/113ms4540 KiB
13Accepted1/121ms4496 KiB
14Accepted2/217ms4488 KiB
15Accepted2/212ms4636 KiB
16Wrong answer0/2223ms4560 KiB
17Wrong answer0/272ms4560 KiB
18Wrong answer0/272ms4560 KiB
19Wrong answer0/375ms4580 KiB
20Wrong answer0/2112ms4560 KiB
21Wrong answer0/2129ms4688 KiB
22Wrong answer0/2215ms4696 KiB
23Wrong answer0/2241ms4828 KiB
24Wrong answer0/2326ms5064 KiB
25Wrong answer0/2120ms5040 KiB
26Wrong answer0/2135ms5040 KiB
27Wrong answer0/274ms5044 KiB
28Wrong answer0/382ms5168 KiB
29Wrong answer0/374ms5252 KiB
30Wrong answer0/374ms5360 KiB