Language: C++


int main() {
    ll N;
    cin >> N;
    vector<ll> A(N);
    rep(i, N) cin >> A[i];
    sort(A.begin(), A.end());

    vector<int> ans(N);
    ans[N/2] = A[0];
    int l = 1, r = N-1;
    int lcur = N/2-1, rcur = N/2+1;
    int turn = 0;

    rep(i, N-1) {
        if (turn%2 == 0) {
            if (r-l+1 >= 2) {
                ans[lcur--] = A[r--];
                ans[rcur++] = A[r--];
            }
            else if (r == l) {
                ans[lcur--] = A[r--];
            }
            turn++;
        }
        else {
            if (r-l+1 >= 2) {
                ans[lcur--] = A[l++];
                ans[rcur++] = A[l++];
            }
            else if (r == l){
                ans[lcur--] = A[l++];
            }
            turn++;
        }
    }

    // cout << endl;
    // rep(i, N) cout << ans[i] << endl;


    vector<ll> ans2(N);
    sort(A.rbegin(), A.rend());
    ans2[N/2] = A[0];
    l = 1, r = N-1;
    lcur = N/2-1, rcur = N/2+1;
    turn = 0;
    rep(i, N-1) {
        if (turn%2 == 0) {
            if (r-l+1 >= 2) {
                ans2[lcur--] = A[r--];
                ans2[rcur++] = A[r--];
            }
            else if (r == l) {
                ans2[lcur--] = A[r--];
            }
            turn++;
        }
        else {
            if (r-l+1 >= 2) {
                ans2[lcur--] = A[l++];
                ans2[rcur++] = A[l++];
            }
            else if (r == l){
                ans2[lcur--] = A[l++];
            }
            turn++;
        }
    }
    //
    // rep(i,N) {
    //     cout << ans2[i] << " ";
    // }
    // cout << endl;

    ll ret1 = 0, ret2 = 0;
    rep(i, N-1) {
        ret1 += llabs(ans[i]-ans[i+1]);
        ret2 += llabs(ans2[i]-ans2[i+1]);
    }
    cout << max(ret1, ret2) << endl;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:3:5: error: 'll' was not declared in this scope
    3 |     ll N;
      |     ^~
a.cc:4:5: error: 'cin' was not declared in this scope
    4 |     cin >> N;
      |     ^~~
a.cc:4:12: error: 'N' was not declared in this scope
    4 |     cin >> N;
      |            ^
a.cc:5:5: error: 'vector' was not declared in this scope
    5 |     vector<ll> A(N);
      |     ^~~~~~
a.cc:5:16: error: 'A' was not declared in this scope
    5 |     vector<ll> A(N);
      |                ^
a.cc:6:9: error: 'i' was not declared in this scope
    6 |     rep(i, N) cin >> A[i];
      |         ^
a.cc:6:5: error: 'rep' was not declared in this scope
    6 |     rep(i, N) cin >> A[i];
      |     ^~~
a.cc:7:5: error: 'sort' was not declared in this scope; did you mean 'short'?
    7 |     sort(A.begin(), A.end());
      |     ^~~~
      |     short
a.cc:9:12: error: expected primary-expression before 'int'
    9 |     vector<int> ans(N);
      |            ^~~
a.cc:10:5: error: 'ans' was not declared in this scope
   10 |     ans[N/2] = A[0];
      |     ^~~
a.cc:42:16: error: 'ans2' was not declared in this scope
   42 |     vector<ll> ans2(N);
      |                ^~~~
a.cc:46:19: error: 'rcur' was not declared in this scope; did you mean 'lcur'?
   46 |     lcur = N/2-1, rcur = N/2+1;
      |                   ^~~~
      |                   lcur
a.cc:76:7: error: expected ';' before 'ret1'
   76 |     ll ret1 = 0, ret2 = 0;
      |       ^~~~~
      |       ;
a.cc:81:5: error: 'cout' was not declared in this scope
   81 |     cout << max(ret1, ret2) << endl;
      |     ^~~~
a.cc:81:17: error: 'ret1' was not declared in this scope
   81 |     cout << max(ret1, ret2) << endl;
      |                 ^~~~
a.cc:81:23: error: 'ret2' was not declared in this scope
   81 |     cout << max(ret1, ret2) << endl;
      |                       ^~~~
a.cc:81:13: error: 'max' was not declared in this scope
   81 |     cout << max(ret1, ret2) << endl;
      |             ^~~
a.cc:81:32: error: 'endl' was not declared in this scope
   81 |     cout << max(ret1, ret2) << endl;
      |                                ^~~~