61532023-11-03 23:32:50MrChipserSípálya (55 pont)cpp11Wrong answer 13/55481ms6168 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;
        }
    }
    int mennyivel = 1;
    for(int i = index-1; i >= 0; i--)
    {
        sz+=abs((akt[index]+mennyivel)-akt[i]);
        //cout << akt[index]+mennyivel << " " << akt[i] << endl;
        mennyivel++;
    }
    mennyivel =1;
    //cout << endl;
    for(int i = index+1; i < k; i++)
    {
        sz+=abs((akt[index]-mennyivel)-akt[i]);
        //cout << akt[index]-mennyivel << " " << akt[i] << endl;
        mennyivel++;
    }
    //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
base13/55
1Accepted0/03ms1888 KiB
2Accepted0/03ms2112 KiB
3Accepted2/23ms2328 KiB
4Accepted2/23ms2540 KiB
5Accepted2/23ms2596 KiB
6Wrong answer0/23ms2816 KiB
7Wrong answer0/33ms2692 KiB
8Wrong answer0/117ms2856 KiB
9Wrong answer0/119ms3140 KiB
10Wrong answer0/123ms3068 KiB
11Accepted1/132ms3332 KiB
12Accepted1/132ms3192 KiB
13Accepted1/171ms3372 KiB
14Accepted2/281ms3348 KiB
15Accepted2/232ms3572 KiB
16Time limit exceeded0/2481ms4424 KiB
17Time limit exceeded0/2472ms5504 KiB
18Time limit exceeded0/2465ms5600 KiB
19Time limit exceeded0/3430ms5944 KiB
20Time limit exceeded0/2472ms4956 KiB
21Time limit exceeded0/2469ms5024 KiB
22Time limit exceeded0/2465ms5116 KiB
23Time limit exceeded0/2472ms5112 KiB
24Time limit exceeded0/2472ms5288 KiB
25Time limit exceeded0/2476ms5672 KiB
26Time limit exceeded0/2444ms5600 KiB
27Time limit exceeded0/2469ms5604 KiB
28Time limit exceeded0/3472ms5712 KiB
29Time limit exceeded0/3465ms5840 KiB
30Time limit exceeded0/3437ms6168 KiB