77542024-01-11 07:54:10csdavidSípálya (55 pont)cpp17Forditási hiba
#include <iostream>

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, e;
    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;
*/


        e=min(nov(palya), csokk(palya));
        if(e<eredmeny){
            eredmeny=e;
        }
        //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;
}
Forditási hiba
exit status 1
main.cpp: In function 'int main()':
main.cpp:59:21: error: 'INT_MAX' was not declared in this scope
   59 |     int n, eredmeny=INT_MAX, e;
      |                     ^~~~~~~
main.cpp:2:1: note: 'INT_MAX' is defined in header '<climits>'; did you forget to '#include <climits>'?
    1 | #include <iostream>
  +++ |+#include <climits>
    2 | 
main.cpp:78:9: error: 'e' was not declared in this scope
   78 |         e=min(nov(palya), csokk(palya));
      |         ^
Exited with error status 1