61522023-11-03 23:17:41MrChipserSípálya (55 pont)cpp11Time limit exceeded 0/55485ms26844 KiB
#include <iostream>
#include <vector>
using namespace std;
int n,k;
long h[200000];
long akt[200000];

int mennyi()
{
    long sz = 0;
    long muveletek = 0;
    do
    {
        muveletek = 0;
        for(int i = 0; i < k-1; i++)
        {
            //cout << akt[i] << " " << akt[i+1] << endl;
            if(akt[i]-1!=akt[i+1])
            {
                sz++;
                muveletek++;
                if(akt[i]-1<akt[i+1])
                    akt[i]++;
                else if(akt[i]-1>akt[i+1])
                    akt[i+1]++;
                else
                    akt[i]++;
            }
            //cout << akt[i] << " " << akt[i+1] << endl;

        }
        //cout << endl;
    }
    while(muveletek!=0);
    for(int j  = 0 ; j < k; j++)
        {
            //cout << akt[j] << " ";
        }
        //cout << endl;
    return sz;
}


int main()
{
    cin >> n >> k;
    for(int i = 0;  i < n; i++)
        cin >> h[i];
    long minim = 1000000001;
    for(int i = 0; i <= n-k; i++)
    {
        int l = 0;
        for(int j  = i ; j < i+k; j++)
        {
            akt[l]=h[j];
            //cout << akt[l] << " ";
            l++;
        }
        //cout << endl;
        long sz = mennyi();
        if(sz<minim)
            minim = sz;
    }
    cout << minim;
    return 0;
}
SubtaskSumTestVerdictTimeMemory
base0/55
1Accepted0/03ms1888 KiB
2Time limit exceeded0/0446ms2084 KiB
3Time limit exceeded0/2425ms1548 KiB
4Time limit exceeded0/2469ms2676 KiB
5Time limit exceeded0/2467ms2912 KiB
6Time limit exceeded0/2476ms2896 KiB
7Time limit exceeded0/3460ms3168 KiB
8Time limit exceeded0/1449ms2680 KiB
9Time limit exceeded0/1469ms3048 KiB
10Time limit exceeded0/1456ms4264 KiB
11Time limit exceeded0/1456ms3484 KiB
12Time limit exceeded0/1485ms3624 KiB
13Time limit exceeded0/1465ms3432 KiB
14Time limit exceeded0/2437ms3520 KiB
15Time limit exceeded0/2481ms3628 KiB
16Time limit exceeded0/2456ms6580 KiB
17Time limit exceeded0/2472ms8464 KiB
18Time limit exceeded0/2456ms9916 KiB
19Time limit exceeded0/3477ms11940 KiB
20Time limit exceeded0/2465ms12388 KiB
21Time limit exceeded0/2474ms13548 KiB
22Time limit exceeded0/2458ms15320 KiB
23Time limit exceeded0/2465ms16552 KiB
24Time limit exceeded0/2458ms18104 KiB
25Time limit exceeded0/2453ms19784 KiB
26Time limit exceeded0/2462ms21148 KiB
27Time limit exceeded0/2465ms22460 KiB
28Time limit exceeded0/3441ms23856 KiB
29Time limit exceeded0/3458ms25424 KiB
30Time limit exceeded0/3453ms26844 KiB