81772024-01-12 15:47:08szabelrSípálya (55 pont)cpp17Wrong answer 18/55469ms5004 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/03ms3416 KiB
2Accepted0/03ms3664 KiB
3Accepted2/24ms3868 KiB
4Accepted2/23ms3908 KiB
5Accepted2/24ms3908 KiB
6Accepted2/24ms4136 KiB
7Wrong answer0/34ms4352 KiB
8Accepted1/114ms4580 KiB
9Accepted1/117ms4708 KiB
10Accepted1/117ms4764 KiB
11Accepted1/125ms4848 KiB
12Accepted1/125ms4864 KiB
13Accepted1/150ms4996 KiB
14Accepted2/257ms5004 KiB
15Accepted2/225ms4856 KiB
16Time limit exceeded0/2448ms3184 KiB
17Time limit exceeded0/2451ms3124 KiB
18Time limit exceeded0/2446ms3296 KiB
19Time limit exceeded0/3433ms3116 KiB
20Time limit exceeded0/2467ms3116 KiB
21Time limit exceeded0/2469ms3308 KiB
22Time limit exceeded0/2449ms3360 KiB
23Time limit exceeded0/2451ms3368 KiB
24Time limit exceeded0/2455ms3436 KiB
25Time limit exceeded0/2465ms3312 KiB
26Time limit exceeded0/2469ms3300 KiB
27Time limit exceeded0/2467ms3328 KiB
28Time limit exceeded0/3455ms3436 KiB
29Time limit exceeded0/3458ms3380 KiB
30Time limit exceeded0/3433ms3272 KiB