77642024-01-11 09:05:59csdavidSípálya (55 pont)cpp17Wrong answer 18/55500ms3652 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;
    int temp = y[0];
    for(int i=0; i<k; i++){
        if(temp<=y[i+1]){
            e=e+(i+1)*(y[i+1]-temp+1);
            temp = y[i+1];
            //cout << y[i] << " < " << y[i+1] << endl;
        }
        else{
            e=e+temp-y[i+1]-1;
            temp=temp-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.tie(NULL);
    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(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
base18/55
1Accepted0/03ms2040 KiB
2Accepted0/03ms2320 KiB
3Accepted2/23ms2392 KiB
4Accepted2/23ms2576 KiB
5Accepted2/23ms2648 KiB
6Accepted2/23ms2784 KiB
7Wrong answer0/33ms3008 KiB
8Accepted1/112ms3220 KiB
9Accepted1/114ms3448 KiB
10Accepted1/116ms3432 KiB
11Accepted1/121ms3516 KiB
12Accepted1/120ms3580 KiB
13Accepted1/146ms3648 KiB
14Accepted2/250ms3624 KiB
15Accepted2/221ms3492 KiB
16Time limit exceeded0/2500ms2688 KiB
17Time limit exceeded0/2469ms3148 KiB
18Time limit exceeded0/2470ms3220 KiB
19Time limit exceeded0/3458ms3200 KiB
20Time limit exceeded0/2477ms2844 KiB
21Time limit exceeded0/2462ms2772 KiB
22Time limit exceeded0/2474ms3520 KiB
23Time limit exceeded0/2469ms3652 KiB
24Time limit exceeded0/2483ms2808 KiB
25Time limit exceeded0/2474ms2784 KiB
26Time limit exceeded0/2451ms2712 KiB
27Time limit exceeded0/2455ms2824 KiB
28Time limit exceeded0/3469ms2864 KiB
29Time limit exceeded0/3469ms2804 KiB
30Time limit exceeded0/3455ms3052 KiB