Language: C++

/* Bismillahirrahmanirrahim */
/* Author : Jehian Norman Saviero (@Reiva5) */
#include <bits/stdc++.h>

// MACROS SAMPAH
#define Jehian using
#define Norman namespace
#define Saviero std

Jehian Norman Saviero;

// MACROS TYPE
typedef long l;
typedef long long ll;
typedef unsigned long ul;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int,int> pi;
typedef pair<l,l> pl;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<l> vl;
typedef vector<ll> vll;

// MACROS FOR PRINT
#define nl printf("\n")
#define sp printf(" ")

// MACROS FOR ATTRIBUTE
#define fi first
#define se second

// MACROS FOR FUNCTION AND METHOD
#define eb emplace_back
#define mp make_pair
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define ALL(x) (x).begin(), (x).end()
#define ALLN(x,n) (x), (x)+(n)
#define CUBE(x) (SQR(x)*(x))
#define SET(x,y) for (int _qwe = sizeof(x)/sizeof(x[0]); _qwe; ) x[--_qwe] = (y)
#define SQR(x) ((x)*(x))
#define SSORT(x,sz) sort(ALLN(x,sz))
#define RESET(x) memset((x), 0, sizeof(x))
#define VSORT(x) sort(ALL(x))

// MACROS READ INPUT
#define sci(x) scanf("%d", &x)
#define scl(x) scanf("%ld", &x)
#define scll(x) scanf("%lld", &x)
#define scul(x) scl(x)
#define scull(x) scll(x)

int main() {
	int N;
	sci(N);
	int arr[N];
	bool any0 = false;
	for (int i = 0; i < N; ++i) sci(arr[i]), any0 = any0 || arr[i] == 0;
	SSORT(arr, N);
	int i;
	vector<pi> ans;
	if (any0) {
		for (i = 0; i < N-1; ++i) {
			if (arr[i] < 0) {
				ans.pb({arr[N-1], arr[i]});
				arr[N-1] -= arr[i];
			} else {
				break;
			}
		}
		if (i < N-2) {
			int last = arr[i];
			++i;
			for (; i < N-1; ++i) {
				ans.pb({last, arr[i]});
				last -= arr[i];
			}
		}
		if (ans.size() < N-1) {
			ans.pb({arr[N-1], last});
		}
	} else {
		int last = arr[0];
		for (i = 1; i < N-1; ++i) {
			ans.pb({last, arr[i]});
			last -= arr[i];
		}
		ans.pb({arr[N-1], last});
	}
	printf("%d\n", ans.back().fi-ans.back().se);
	for (pi &it : ans) {
		printf("%d %d\n", it.fi, it.se);
	}
	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:83:43: error: 'last' was not declared in this scope
   83 |                         ans.pb({arr[N-1], last});
      |                                           ^~~~
a.cc:83:31: error: no matching function for call to 'std::vector<std::pair<int, int> >::push_back(<brace-enclosed initializer list>)'
   83 |                         ans.pb({arr[N-1], last});
      |                         ~~~~~~^~~~~~~~~~~~~~~~~~
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:3:
/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<int, int>; _Alloc = std::allocator<std::pair<int, int> >; value_type = std::pair<int, int>]'
 1283 |       push_back(const value_type& __x)
      |       ^~~~~~~~~
/usr/include/c++/14/bits/stl_vector.h:1283:35: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'const std::vector<std::pair<int, int> >::value_type&' {aka 'const std::pair<int, int>&'}
 1283 |       push_back(const value_type& __x)
      |                 ~~~~~~~~~~~~~~~~~~^~~
/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<int, int>; _Alloc = std::allocator<std::pair<int, int> >; value_type = std::pair<int, int>]'
 1300 |       push_back(value_type&& __x)
      |       ^~~~~~~~~
/usr/include/c++/14/bits/stl_vector.h:1300:30: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'std::vector<std::pair<int, int> >::value_type&&' {aka 'std::pair<int, int>&&'}
 1300 |       push_back(value_type&& __x)
      |                 ~~~~~~~~~~~~~^~~