77552024-01-11 07:55:36csdavidSípálya (55 pont)cpp17Wrong answer 0/55500ms4424 KiB
#include <iostream>
#include <climits>

using namespace std;
int k;

void csere(int x123[])
{
    for(int i=0; i<k; i++){
        x123[i]=x123[i+1];
    }
}

int nov(int y[])
{
    int e=0;
    for(int i=0; i<k; i++){
        if(y[i]<y[i+1]){
            e=e+(i+1)*(y[i+1]-y[i]-1);
            //cout << y[i] << " < " << y[i+1] << endl;
        }
        else if(y[i]==y[i+1]){
            y[i+1]++;
            e++;
            //cout << y[i] << " = " << y[i+1] << endl;

        }
        else{
            e=e+y[i]-y[i+1]+1;
            y[i+1]=y[i]-y[i+1]+1;
            //cout << y[i] << " > " << y[i+1] << endl;
        }
    }
    return e;
}

int csokk(int y[])
{
    int e=0;
    for(int i=k; i>0; i--){
        if(y[i]<y[i-1]){
            e=e+(i-1)*(y[i-1]-y[i]-1);
        }
        else if(y[i]==y[i-1]){
            y[i-1]++;
            e++;
        }
        else{
            e=e+y[i]-y[i-1]+1;
            y[i-1]=y[i]-y[i-1]+1;
        }
    }
    return e;
}



int main()
{
    int n, eredmeny=INT_MAX, g;
    ios_base::sync_with_stdio(false);
    cin >> n >> k;
    k--;
    int palya[k+1];
    for(int i=0; i<k; i++){
        cin >> palya[i];
    }

    for(int i=k; i<n; i++){
        cin >> palya[k];
        /*cout << "palya: ";
        for(int i=0; i<=k; i++){
        cout << palya[i]
    }
        cout << endl;
*/


        g=min(nov(palya), csokk(palya));
        if(g<eredmeny){
            eredmeny=g;
        }
        //cout << e << endl;
        csere(palya);
    }
    cout << eredmeny;




    /*k=4;
    int a[5] = {3, 4, 3, 1, 1};
    int x = csokk(a);
    cout << x;*/












    return 0;
}
SubtaskSumTestVerdictTimeMemory
base0/55
1Wrong answer0/03ms2032 KiB
2Wrong answer0/03ms2248 KiB
3Wrong answer0/23ms2336 KiB
4Wrong answer0/23ms2464 KiB
5Wrong answer0/24ms2568 KiB
6Wrong answer0/24ms2660 KiB
7Wrong answer0/34ms2732 KiB
8Wrong answer0/148ms2940 KiB
9Wrong answer0/161ms3148 KiB
10Wrong answer0/171ms3228 KiB
11Wrong answer0/137ms3224 KiB
12Wrong answer0/137ms3224 KiB
13Wrong answer0/182ms3232 KiB
14Wrong answer0/293ms3336 KiB
15Wrong answer0/239ms3324 KiB
16Time limit exceeded0/2467ms2664 KiB
17Time limit exceeded0/2465ms3080 KiB
18Time limit exceeded0/2470ms2940 KiB
19Time limit exceeded0/3469ms3212 KiB
20Time limit exceeded0/2430ms3736 KiB
21Time limit exceeded0/2469ms3632 KiB
22Time limit exceeded0/2449ms3676 KiB
23Time limit exceeded0/2465ms3816 KiB
24Time limit exceeded0/2474ms4012 KiB
25Time limit exceeded0/2465ms3096 KiB
26Time limit exceeded0/2453ms3276 KiB
27Time limit exceeded0/2449ms4344 KiB
28Time limit exceeded0/3446ms4424 KiB
29Time limit exceeded0/3465ms3580 KiB
30Time limit exceeded0/3500ms3584 KiB