61542023-11-03 23:49:14MrChipserSípálya (55 pont)cpp11Wrong answer 13/55485ms5960 KiB
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;
int n,k;
long h[200000];
long akt[200000];

int mennyi()
{
    long sz = 0;
    int maxim = 0;
    int index;
    for(int i = 0; i < k; i++)
    {
        if(maxim < akt[i])
        {
            maxim = akt[i];
            index = i;
        }
        else if(maxim == akt[i])
        {
           maxim+=i-index;
           sz+=i-index;

        }
    }
    int mennyivel = 0;
    int elso = maxim+index;
    //cout << elso << endl;
    for(int i = 0; i < k; i++)
    {
        sz+=abs((elso-mennyivel)-akt[i]);
        //cout << akt[index]+mennyivel << " " << akt[i] << endl;
        mennyivel++;
    }

    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
base13/55
1Accepted0/03ms1760 KiB
2Accepted0/03ms1924 KiB
3Accepted2/23ms2148 KiB
4Accepted2/23ms2360 KiB
5Accepted2/23ms2580 KiB
6Wrong answer0/24ms2784 KiB
7Wrong answer0/33ms2888 KiB
8Wrong answer0/117ms3216 KiB
9Wrong answer0/118ms3216 KiB
10Wrong answer0/120ms3476 KiB
11Accepted1/128ms3440 KiB
12Accepted1/128ms3624 KiB
13Accepted1/163ms3844 KiB
14Accepted2/271ms4068 KiB
15Accepted2/229ms3996 KiB
16Time limit exceeded0/2477ms4652 KiB
17Time limit exceeded0/2485ms5424 KiB
18Time limit exceeded0/2485ms5548 KiB
19Time limit exceeded0/3453ms5924 KiB
20Time limit exceeded0/2460ms4828 KiB
21Time limit exceeded0/2462ms4836 KiB
22Time limit exceeded0/2453ms5276 KiB
23Time limit exceeded0/2476ms5120 KiB
24Time limit exceeded0/2462ms5364 KiB
25Time limit exceeded0/2453ms5492 KiB
26Time limit exceeded0/2465ms5432 KiB
27Time limit exceeded0/2462ms5912 KiB
28Time limit exceeded0/3462ms5780 KiB
29Time limit exceeded0/3446ms5876 KiB
30Time limit exceeded0/3437ms5960 KiB