77632024-01-11 08:53:42csdavidSípálya (55 pont)cpp17Wrong answer 18/55486ms3696 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{
            e=e+y[i]-y[i+1]-1;
            y[i+1]=y[i]-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], picula[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;*/

        for(int i=0; i<=k; i++){
            picula[i]=palya[i];
        }

        //g=min(nov(palya), csokk(palya));
        g=nov(picula);

        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
base18/55
1Accepted0/03ms1928 KiB
2Accepted0/03ms2156 KiB
3Accepted2/23ms2308 KiB
4Accepted2/23ms2664 KiB
5Accepted2/23ms2768 KiB
6Accepted2/23ms2944 KiB
7Wrong answer0/33ms3028 KiB
8Accepted1/114ms3052 KiB
9Accepted1/116ms3276 KiB
10Accepted1/117ms3264 KiB
11Accepted1/128ms3132 KiB
12Accepted1/127ms3356 KiB
13Accepted1/159ms3508 KiB
14Accepted2/265ms3388 KiB
15Accepted2/228ms3364 KiB
16Time limit exceeded0/2460ms2564 KiB
17Time limit exceeded0/2449ms3332 KiB
18Time limit exceeded0/2453ms3264 KiB
19Time limit exceeded0/3442ms3696 KiB
20Time limit exceeded0/2467ms2644 KiB
21Time limit exceeded0/2486ms2592 KiB
22Time limit exceeded0/2446ms3560 KiB
23Time limit exceeded0/2449ms3384 KiB
24Time limit exceeded0/2462ms2744 KiB
25Time limit exceeded0/2451ms2920 KiB
26Time limit exceeded0/2453ms2996 KiB
27Time limit exceeded0/2462ms3240 KiB
28Time limit exceeded0/3458ms3268 KiB
29Time limit exceeded0/3474ms3276 KiB
30Time limit exceeded0/3462ms3224 KiB