Language: C++

#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
long long mo = 1e9 + 7;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<class A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}cout << "\n";}
ld PI=3.14159265358979323846;

int main(){
    ll N;
    cin >> N;
    deque<ll> A(N);
    rep(i,N){
        cin >> A[i];
    }
    vector<deque> m,p;
    rep(i,N){
        if(A[i] >= 0){
            p.push_back(A[i]);
        }else{
            m.push_back(A[i]);
        }
    }
    sort(p.begin(),p.end());
    sort(m.begin(),m.end());
    vector<Pll> v;
    if(N == 2){
        cout << max(A[0],A[1]) - min(A[0],A[1]) << endl;
        cout << max(A[0], A[1]) << " " << min(A[0], A[1]) << endl;
        return 0;
    }
    rep(i,N-1){
        ll t1,t2;
        if(p.empty()){
            t1 = m.front();
            m.pop_front();
            t2 = m.back();
            m.pop_back();
            if(t1 > t2){
                v.push_back(Pll(t1,t2));
            }else{
                v.push_back(Pll(t2,t1));
            }
            p.push_back(abs(t1-t2));
        }else if(m.empty()){
            t1 = p.front();
            p.pop_back();
            t2 = p.front();
            p.pop_back();
            if(p.empty()){
                if(t1>t2){
                    v.push_back(Pll(t1,t2));
                }else{
                    v.push_back(Pll(t2,t1));
                }
                p.push_back(abs(t1-t2));
                continue;
            }else if(t1>t2){
                v.push_back(Pll(t2, t1));
            }else{
                v.push_back(Pll(t1, t2));
            }
            m.push_back(-abs(t1-t2));
        }else{
            t1 = p.back();
            p.pop_back();
            t2 = m.back();
            m.pop_back();
            if(p.empty()){
                v.push_back(Pll(t1,t2));
                p.push_back(t1-t2);
            }else{
                v.push_back(Pll(t2,t1));
                m.push_back(t2-t1);
            }
        }
    }
    cout << p.back() << endl;
    rep(i,N-1){
        cout << v[i].first << " " << v[i].second << endl;
    }
    /*
    rep(i,N-1){
        ll t1 = A.front();
        ll t2 = A.back();
        A.pop_front();
        A.pop_back();
        v.push_back(Pll(t2,t1));
        ll u = t2-t1;
        auto itr = lower_bound(A.begin(), A.end(), u);
        A.insert(itr, u);
    }
    cout << A[0] << endl;
    rep(i,N-1){
        cout << v[i].first << " " << v[i].second << endl;
    }
    /*
    bool pflag = true;
    bool mflag = true;
    rep(i,N){
        if(A[i] < 0){
            pflag = false;
            break;
        }
    }
    rep(i,N){
        if(A[i] >= 0){
            mflag = false; 
            break;
        }
    }
    ll ans = 0;
    vector<Pll> v;
    if(mflag || pflag){
        rep(i,N){
            A[i] = abs(A[i]);
        }
        sort(A.begin(), A.end());
        ans -= A[0];
        REP(i,1,N){
            ans += A[i];
        }
    }else{
        rep(i,N){
            ans += abs(A[i]);
        }
    }
    cout << ans << endl;*/
}

Compiler output:
a.cc: In function 'int main()':
a.cc:22:17: error: type/value mismatch at argument 1 in template parameter list for 'template<class _Tp, class _Alloc> class std::vector'
   22 |     vector<deque> m,p;
      |                 ^
a.cc:22:17: note:   expected a type, got 'deque'
a.cc:22:17: error: template argument 2 is invalid
a.cc:25:15: error: request for member 'push_back' in 'p', which is of non-class type 'int'
   25 |             p.push_back(A[i]);
      |               ^~~~~~~~~
a.cc:27:15: error: request for member 'push_back' in 'm', which is of non-class type 'int'
   27 |             m.push_back(A[i]);
      |               ^~~~~~~~~
a.cc:30:12: error: request for member 'begin' in 'p', which is of non-class type 'int'
   30 |     sort(p.begin(),p.end());
      |            ^~~~~
a.cc:30:22: error: request for member 'end' in 'p', which is of non-class type 'int'
   30 |     sort(p.begin(),p.end());
      |                      ^~~
a.cc:31:12: error: request for member 'begin' in 'm', which is of non-class type 'int'
   31 |     sort(m.begin(),m.end());
      |            ^~~~~
a.cc:31:22: error: request for member 'end' in 'm', which is of non-class type 'int'
   31 |     sort(m.begin(),m.end());
      |                      ^~~
a.cc:40:14: error: request for member 'empty' in 'p', which is of non-class type 'int'
   40 |         if(p.empty()){
      |              ^~~~~
a.cc:41:20: error: request for member 'front' in 'm', which is of non-class type 'int'
   41 |             t1 = m.front();
      |                    ^~~~~
a.cc:42:15: error: request for member 'pop_front' in 'm', which is of non-class type 'int'
   42 |             m.pop_front();
      |               ^~~~~~~~~
a.cc:43:20: error: request for member 'back' in 'm', which is of non-class type 'int'
   43 |             t2 = m.back();
      |                    ^~~~
a.cc:44:15: error: request for member 'pop_back' in 'm', which is of non-class type 'int'
   44 |             m.pop_back();
      |               ^~~~~~~~
a.cc:50:15: error: request for member 'push_back' in 'p', which is of non-class type 'int'
   50 |             p.push_back(abs(t1-t2));
      |               ^~~~~~~~~
a.cc:51:20: error: request for member 'empty' in 'm', which is of non-class type 'int'
   51 |         }else if(m.empty()){
      |                    ^~~~~
a.cc:52:20: error: request for member 'front' in 'p', which is of non-class type 'int'
   52 |             t1 = p.front();
      |                    ^~~~~
a.cc:53:15: error: request for member 'pop_back' in 'p', which is of non-class type 'int'
   53 |             p.pop_back();
      |               ^~~~~~~~
a.cc:54:20: error: request for member 'front' in 'p', which is of non-class type 'int'
   54 |             t2 = p.front();
      |                    ^~~~~
a.cc:55:15: error: request for member 'pop_back' in 'p', which is of non-class type 'int'
   55 |             p.pop_back();
      |               ^~~~~~~~
a.cc:56:18: error: request for member 'empty' in 'p', which is of non-class type 'int'
   56 |             if(p.empty()){
      |                  ^~~~~
a.cc:62:19: error: request for member 'push_back' in 'p', which is of non-class type 'int'
   62 |                 p.push_back(abs(t1-t2));
      |                   ^~~~~~~~~
a.cc:69:15: error: request for member 'push_back' in 'm', which is of non-class type 'int'
   69 |             m.push_back(-abs(t1-t2));
      |               ^~~~~~~~~
a.cc:71:20: error: request for member 'back' in 'p', which is of non-class type 'int'
   71 |             t1 = p.back();
      |                    ^~~~
a.cc:72:15: error: request for member 'pop_back' in 'p', which is of non-class type 'int'
   72 |             p.pop_back();
      |               ^~~~~~~~
a.cc:73:20: error: request for member 'back' in 'm', which is of non-class type 'int'
   73 |             t2 = m.back();
      |                    ^~~~
a.cc:74:15: error: request for member 'pop_back' in 'm', which is of non-class type 'int'
   74 |             m.pop_back();
      |               ^~~~~~~~
a.cc:75:18: error: request for member 'empty' in 'p', which is of non-class type 'int'
   75 |             if(p.empty()){
      |                  ^~~~~
a.cc:77:19: error: request for member 'push_back' in 'p', which is of non-class type 'int'
   77 |                 p.push_back(t1-t2);
      |                   ^~~~~~~~~
a.cc:80:19: error: request for member 'push_back' in 'm', which is of non-class type 'int'
   80 |                 m.push_back(t2-t1);
      |                   ^~~~~~~~~
a.cc:84:15: error: request for member 'back' in 'p', which is of non-class type 'int'
   84 |     cout << p.back() << endl;
      |               ^~~~