Language: C++

// IOI 2021
#include <bits/stdc++.h>
using namespace std;

#define endl '\n'
#define ends ' '
#define die(x) return cout << x << endl, 0
#define all(v) v.begin(), v.end()
#define sz(x) (int)(x.size())
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) { cerr << ends << H; debug_out(T...); }
#define debug(...) cerr << "{" << #__VA_ARGS__ << "}:", debug_out(__VA_ARGS__)
typedef long long ll;
typedef pair<int, int> pii;
const ll INF = 1e9;
const ll MOD = 1e9 + 7;

////////////////////////////////////////////////////////////////////

const int N = 1e5 + 5;

int A[N], B[N];

int main() {

	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);

	int n; cin >> n;
	for (int i = 0; i < n; i++) cin >> A[i];
	sort(A, A + n);
	int p = 0, q = n, x = 0;
	while (p < q) {
		if (x & 1) B[x++] = A[p++];
		else B[x++] = A[--q];
	}
	ll sum = abs(B[n - 1] - B[0]), mn = sum;
	for (int i = 0; i < n - 1; i++) sum += abs(B[i + 1] - B[i]), mn = min(abs(B[i + 1] - B[i]), mn);
	cout << sum - mn << endl;

	return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:38:78: error: no matching function for call to 'min(int, ll&)'
   38 |         for (int i = 0; i < n - 1; i++) sum += abs(B[i + 1] - B[i]), mn = min(abs(B[i + 1] - B[i]), mn);
      |                                                                           ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51,
                 from a.cc:2:
/usr/include/c++/14/bits/stl_algobase.h:233:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)'
  233 |     min(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:233:5: note:   template argument deduction/substitution failed:
a.cc:38:78: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'll' {aka 'long long int'})
   38 |         for (int i = 0; i < n - 1; i++) sum += abs(B[i + 1] - B[i]), mn = min(abs(B[i + 1] - B[i]), mn);
      |                                                                           ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)'
  281 |     min(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note:   candidate expects 3 arguments, 2 provided
In file included from /usr/include/c++/14/algorithm:61:
/usr/include/c++/14/bits/stl_algo.h:5686:5: note: candidate: 'template<class _Tp> constexpr _Tp std::min(initializer_list<_Tp>)'
 5686 |     min(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5686:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5696:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::min(initializer_list<_Tp>, _Compare)'
 5696 |     min(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5696:5: note:   template argument deduction/substitution failed:
a.cc:38:78: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   38 |         for (int i = 0; i < n - 1; i++) sum += abs(B[i + 1] - B[i]), mn = min(abs(B[i + 1] - B[i]), mn);
      |                                                                           ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~