81812024-01-12 16:02:53szabelrSípálya (55 pont)cpp17Wrong answer 18/55481ms6492 KiB
#include <iostream>

using namespace std;

long epit(long h[], int s, int K, int N) {
    int maxi = 0;
    for (int i = 0; i < K and s+i<N; 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; */

    long hs = 0;
    for (int i = 0; i < K and s+i<N; i++) hs += h[s + i];

    return K * (K - 1) / 2 + K * m - hs;
}

int main() {

    long  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/04ms4972 KiB
2Accepted0/04ms5184 KiB
3Accepted2/24ms5272 KiB
4Accepted2/24ms5400 KiB
5Accepted2/24ms5448 KiB
6Accepted2/24ms5576 KiB
7Wrong answer0/34ms5680 KiB
8Accepted1/117ms5888 KiB
9Accepted1/120ms6252 KiB
10Accepted1/123ms6124 KiB
11Accepted1/129ms6132 KiB
12Accepted1/128ms6256 KiB
13Accepted1/161ms6340 KiB
14Accepted2/268ms6488 KiB
15Accepted2/229ms6492 KiB
16Time limit exceeded0/2470ms4004 KiB
17Time limit exceeded0/2458ms4228 KiB
18Time limit exceeded0/2481ms4332 KiB
19Time limit exceeded0/3458ms4496 KiB
20Time limit exceeded0/2467ms4604 KiB
21Time limit exceeded0/2453ms4524 KiB
22Time limit exceeded0/2472ms4576 KiB
23Time limit exceeded0/2462ms4428 KiB
24Time limit exceeded0/2467ms4708 KiB
25Time limit exceeded0/2469ms4700 KiB
26Time limit exceeded0/2474ms4804 KiB
27Time limit exceeded0/2458ms4696 KiB
28Time limit exceeded0/3458ms4624 KiB
29Time limit exceeded0/3477ms4700 KiB
30Time limit exceeded0/3474ms4632 KiB