Language: C++

#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define MOD 1000000007LL
#define REP(i, n) for(int i=0;i<(n);++i)
// typedef long long ll;
#define int long long

signed main(){
	cin.tie(0);
	ios::sync_with_stdio(false);

	typedef pair<int, int> P;
	vector<P> vec;
	int N, A[100000]; cin >> N;
	REP(i, N) cin >> A[i];
	sort(A, A+N);
	int ans = 0;
	REP(i, N/2){
		if(i == 0){
			if(N % 2 == 0 or (N % 2 == 1 and A[N/2] < 0)){
				vec.push_back(P(A[N-1-i], A[i]));
			} else {
				vec.push_back(P(A[i], A[N-1-i]));
			}
		} else {
			if(N % 2 == 0 or (N % 2 == 1 and A[N/2] < 0)){
				vec.push_back(P(A[i], A[N-1-i]));
				vec.push_back(P(ans, abs(A[i]-A[N-1-i])));
			} else {
				vec.push_back(P(A[N-1-i], A[i]));
				vec.push_back(P(ans, abs(A[i]-A[N-1-i])));
			}
		}
		ans += abs(A[i]-A[N-1-i]);
	}
	if(N % 2 == 1){
		if(A[N/2] >= 0){
			vec.push_back(A[N/2], ans);
		} else {
			vec.push_back(ans, A[N/2]);
		}
		ans += A[N/2];
	}
	cout << ans << endl;
	REP(i, vec.size()){
		cout << vec[i].first << ' ' << vec[i].second << endl;
	}
}


Compiler output:
a.cc: In function 'int main()':
a.cc:39:38: error: no matching function for call to 'std::vector<std::pair<long long int, long long int> >::push_back(long long int&, long long int&)'
   39 |                         vec.push_back(A[N/2], ans);
      |                         ~~~~~~~~~~~~~^~~~~~~~~~~~~
In file included from /usr/include/c++/14/vector:66,
                 from /usr/include/c++/14/functional:64,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:53,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_vector.h:1283:7: note: candidate: 'void std::vector<_Tp, _Alloc>::push_back(const value_type&) [with _Tp = std::pair<long long int, long long int>; _Alloc = std::allocator<std::pair<long long int, long long int> >; value_type = std::pair<long long int, long long int>]'
 1283 |       push_back(const value_type& __x)
      |       ^~~~~~~~~
/usr/include/c++/14/bits/stl_vector.h:1283:7: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_vector.h:1300:7: note: candidate: 'void std::vector<_Tp, _Alloc>::push_back(value_type&&) [with _Tp = std::pair<long long int, long long int>; _Alloc = std::allocator<std::pair<long long int, long long int> >; value_type = std::pair<long long int, long long int>]'
 1300 |       push_back(value_type&& __x)
      |       ^~~~~~~~~
/usr/include/c++/14/bits/stl_vector.h:1300:7: note:   candidate expects 1 argument, 2 provided
a.cc:41:38: error: no matching function for call to 'std::vector<std::pair<long long int, long long int> >::push_back(long long int&, long long int&)'
   41 |                         vec.push_back(ans, A[N/2]);
      |                         ~~~~~~~~~~~~~^~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_vector.h:1283:7: note: candidate: 'void std::vector<_Tp, _Alloc>::push_back(const value_type&) [with _Tp = std::pair<long long int, long long int>; _Alloc = std::allocator<std::pair<long long int, long long int> >; value_type = std::pair<long long int, long long int>]'
 1283 |       push_back(const value_type& __x)
      |       ^~~~~~~~~
/usr/include/c++/14/bits/stl_vector.h:1283:7: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_vector.h:1300:7: note: candidate: 'void std::vector<_Tp, _Alloc>::push_back(value_type&&) [with _Tp = std::pair<long long int, long long int>; _Alloc = std::allocator<std::pair<long long int, long long int> >; value_type = std::pair<long long int, long long int>]'
 1300 |       push_back(value_type&& __x)
      |       ^~~~~~~~~
/usr/include/c++/14/bits/stl_vector.h:1300:7: note:   candidate expects 1 argument, 2 provided