81822024-01-12 16:19:42szabelrSípálya (55 pont)cpp17Wrong answer 18/55483ms5064 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/03ms3420 KiB
2Accepted0/03ms3652 KiB
3Accepted2/24ms3972 KiB
4Accepted2/24ms4096 KiB
5Accepted2/24ms4232 KiB
6Accepted2/24ms4184 KiB
7Wrong answer0/34ms4308 KiB
8Accepted1/116ms4492 KiB
9Accepted1/117ms4556 KiB
10Accepted1/120ms4556 KiB
11Accepted1/128ms4748 KiB
12Accepted1/128ms4824 KiB
13Accepted1/157ms5064 KiB
14Accepted2/265ms5044 KiB
15Accepted2/228ms5040 KiB
16Time limit exceeded0/2467ms3536 KiB
17Time limit exceeded0/2458ms3588 KiB
18Time limit exceeded0/2465ms3764 KiB
19Time limit exceeded0/3425ms3704 KiB
20Time limit exceeded0/2483ms3724 KiB
21Time limit exceeded0/2477ms3704 KiB
22Time limit exceeded0/2465ms3636 KiB
23Time limit exceeded0/2465ms3704 KiB
24Time limit exceeded0/2470ms3680 KiB
25Time limit exceeded0/2451ms3708 KiB
26Time limit exceeded0/2455ms4096 KiB
27Time limit exceeded0/2469ms4136 KiB
28Time limit exceeded0/3462ms4200 KiB
29Time limit exceeded0/3474ms4228 KiB
30Time limit exceeded0/3477ms4448 KiB