Language: C++

#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <stack>
#include <vector>
#include <queue>
#include <random>
#include <cstdint>
#include <bitset>
#include <iomanip>
#include <utility>
#include<map>
#include<functional>
#include<climits>
using namespace std;
using ll = long long;
const int mod = 1000000007;

int main() {
	ll n, a[100000], b[100000];
		vector<ll> awant,bwant;
	bool used[100000];
	fill(used, used + 100000, false);
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i] >> b[i];
	}
	for (int i = 0; i < n; i++) {
		awant.push_back( i);
		bwant.push_back( i);
	}
	sort(awant.begin(), awant.end(), [](auto &left, auto &right) {
		if(left!=right)return a[left] < a[right];
		else return b[left] > b[right];
	});
	sort(bwant.begin(), bwant.end(), [](auto &left, auto &right) {
		if (left != right)return b[left] < b[right];
		else return a[left] > a[right];
	});
	int anum = 0, bnum = 0;
	ll ans = 0;
	int asd = n;
	while (asd!=0) {
		while (used[awant[anum]])anum++;
		while (used[bwant[bnum]])bnum++;
		int memo = bnum+1;
		while (used[bwant[memo]])memo++;
		if (a[anum] - b[bnum] > a[bnum] - b[memo]) {
			ans += a[anum] - b[bnum];
			used[anum] = true;
			used[bnum] = true;
			asd--;
		}
		else {
			ans += a[bnum] - b[memo];
			used[memo] = true;
			used[bnum] = true;
			asd--;
		}

	}
	cout << ans << endl;
}

Compiler output:
a.cc: In lambda function:
a.cc:34:39: error: 'a' is not captured
   34 |                 if(left!=right)return a[left] < a[right];
      |                                       ^
a.cc:33:43: note: the lambda has no capture-default
   33 |         sort(awant.begin(), awant.end(), [](auto &left, auto &right) {
      |                                           ^
a.cc:21:15: note: 'll a [100000]' declared here
   21 |         ll n, a[100000], b[100000];
      |               ^
a.cc:34:49: error: 'a' is not captured
   34 |                 if(left!=right)return a[left] < a[right];
      |                                                 ^
a.cc:33:43: note: the lambda has no capture-default
   33 |         sort(awant.begin(), awant.end(), [](auto &left, auto &right) {
      |                                           ^
a.cc:21:15: note: 'll a [100000]' declared here
   21 |         ll n, a[100000], b[100000];
      |               ^
a.cc:35:29: error: 'b' is not captured
   35 |                 else return b[left] > b[right];
      |                             ^
a.cc:33:43: note: the lambda has no capture-default
   33 |         sort(awant.begin(), awant.end(), [](auto &left, auto &right) {
      |                                           ^
a.cc:21:26: note: 'll b [100000]' declared here
   21 |         ll n, a[100000], b[100000];
      |                          ^
a.cc:35:39: error: 'b' is not captured
   35 |                 else return b[left] > b[right];
      |                                       ^
a.cc:33:43: note: the lambda has no capture-default
   33 |         sort(awant.begin(), awant.end(), [](auto &left, auto &right) {
      |                                           ^
a.cc:21:26: note: 'll b [100000]' declared here
   21 |         ll n, a[100000], b[100000];
      |                          ^
a.cc: In lambda function:
a.cc:38:42: error: 'b' is not captured
   38 |                 if (left != right)return b[left] < b[right];
      |                                          ^
a.cc:37:43: note: the lambda has no capture-default
   37 |         sort(bwant.begin(), bwant.end(), [](auto &left, auto &right) {
      |                                           ^
a.cc:21:26: note: 'll b [100000]' declared here
   21 |         ll n, a[100000], b[100000];
      |                          ^
a.cc:38:52: error: 'b' is not captured
   38 |                 if (left != right)return b[left] < b[right];
      |                                                    ^
a.cc:37:43: note: the lambda has no capture-default
   37 |         sort(bwant.begin(), bwant.end(), [](auto &left, auto &right) {
      |                                           ^
a.cc:21:26: note: 'll b [100000]' declared here
   21 |         ll n, a[100000], b[100000];
      |                          ^
a.cc:39:29: error: 'a' is not captured
   39 |                 else return a[left] > a[right];
      |                             ^
a.cc:37:43: note: the lambda has no capture-default
   37 |         sort(bwant.begin(), bwant.end(), [](auto &left, auto &right) {
      |                                           ^
a.cc:21:15: note: 'll a [100000]' declared here
   21 |         ll n, a[100000], b[100000];
      |               ^
a.cc:39:39: error: 'a' is not captured
   39 |                 else return a[left] > a[right];
      |                                       ^
a.cc:37:43: note: the lambda has no capture-default
   37 |         sort(bwant.begin(), bwant.end(), [](auto &left, auto &right) {
      |                                           ^
a.cc:21:15: note: 'll a [100000]' declared here
   21 |         ll n, a[100000], b[100000];
      |               ^
In file included from /usr/include/c++/14/bits/stl_algobase.h:71,
                 from /usr/include/c++/14/string:51,
                 from /usr/include/c++/14/bits/locale_classes.h:40,
                 from /usr/include/c++/14/bits/ios_base.h:41,
                 from /usr/include/c++/14/ios:44,
                 from /usr/include/c++/14/ostream:40,
                 from /usr/include/c++/14/iostream:41,
                 from a.cc:1:
/usr/include/c++/14/bits/predefined_ops.h: In instantiation of 'constexpr bool __gnu_cxx::__ops::_Iter_comp_iter<_Compare>::operator()(_Iterator1, _Iterator2) [with _Iterator1 = __gnu_cxx::__normal_iterator<long long int*, std::vector<long long int> >; _Iterator2 = __gnu_cxx::__normal_iterator<long long int*, std::vector<long long int> >; _Compare = main()::<lambda(auto:1&, auto:2&)>]':
/usr/include/c++/14/bits/stl_algo.h:1777:14:   required from 'void std::__insertion_sort(_RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<long long int*, vector<long long int> >; _Compare = __gnu_cxx::__ops::_Iter_comp_iter<main()::<lambda(auto:1&, auto:2&)> >]'
 1777 |           if (__comp(__i, __first))
      |               ~~~~~~^~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algo.h:1817:25:   required from 'void std::__final_insertion_sort(_RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<long long int*, vector<long long int> >; _Compare = __gnu_cxx::__ops::_Iter_comp_iter<main()::<lambda(auto:1&, auto:2&)> >]'
 1817 |           std::__insertion_sort(__first, __first + int(_S_threshold), __comp);
      |           ~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algo.h:1908:31:   required from 'void std::__sort(_RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<long long int*, vector<long long int> >; _Compare = __gnu_cxx::__ops::_Iter_comp_iter<main()::<lambda(auto:1&, auto:2&)> >]'
 1908 |           std::__final_insertion_sort(__first, __last, __comp);
      |           ~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algo.h:4805:18:   required from 'void std::sort(_RAIter, _RAIter, _Compare) [with _RAIter = __gnu_cxx::__normal_iterator<long long int*, vector<long long int> >; _Compare = main()::<lambda(auto:1&, auto:2&)>]'
 4805 |       std::__sort(__first, __last, __gnu_cxx::__ops::__iter_comp_iter(__comp));
      |       ~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:33:6:   required from here
   33 |         sort(awant.begin(), awant.end(), [](auto &left, auto &right) {
      |         ~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   34 |                 if(left!=right)return a[left] < a[right];
      |                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   35 |                 else return b[left] > b[right];
      |                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   36 |         });
      |         ~~   
/usr/include/c++/14/bits/predefined_ops.h:158:30: error: void value not ignored as it ought to be
  158 |         { return bool(_M_comp(*__it1, *__it2)); }
      |                       ~~~~~~~^~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/predefined_ops.h: In instantiation of 'constexpr bool __gnu_cxx::__ops::_Iter_comp_iter<_Compare>::operator()(_Iterator1, _Iterator2) [with _Iterator1 = __gnu_cxx::__normal_iterator<long long int*, std::vector<long long int> >; _Iterator2 = __gnu_cxx::__normal_iterator<long long int*, std::vector<long long int> >; _Compare = main()::<lambda(auto:3&, auto:4&)>]':
/usr/include/c++/14/bits/stl_algo.h:1777:14:   required from 'void std::__insertion_sort(_RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<long long int*, vector<long long int> >; _Compare = __gnu_cxx::__ops::_Iter_comp_iter<main()::<lambda(auto:3&, auto:4&)> >]'
 1777 |           if (__comp(__i, __first))
      |               ~~~~~~^~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algo.h:1817:25:   required from 'void std::__final_insertion_sort(_RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<long long int*, vector<long long int> >; _Compare = __gnu_cxx::__ops::_Iter_comp_iter<main()::<lambda(auto:3&, auto:4&)> >]'
 1817 |           std::__insertion_sort(__first, __first + int(_S_threshold), __comp);
      |           ~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algo.h:1908:31:   required from 'void std::__sort(_RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<long long int*, vector<long long int> >; _Compare = __gnu_cxx::__ops::_Iter_comp_iter<main()::<lambda(auto:3&, auto:4&)> >]'
 1908 |           std::__final_insertion_sort(__first, __last, __comp);
      |           ~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algo.h:4805:18:   required from 'void std::sort(_RAIter, _RAIter, _Compare) [with _RAIter = __gnu_cxx::__normal_iterator<long long int*, vector<long long int> >; _Compare = main()::<lambda(auto:3&, auto:4&)>]'
 4805 |       std::__sort(__first, __last, __gnu_cxx::__ops::__iter_comp_iter(__comp));
      |       ~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:37:6:   required from here
   37 |         sort(bwant.begin(), bwant.end(), [](auto &left, auto &right) {
      |         ~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   38 |                 if (left != right)return b[left] < b[right];
      |                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   39 |                 else return a[left] > a[right];
      |                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   40 |         });
      |         ~~   
/usr/include/c++/14/bits/predefined_ops.h:158:30: error: void value not ignored as it ought to be
  158 |         { return bool(_M_comp(*__it1, *__it2)); }
      |                       ~~~~~~~^~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/predefined_ops.h: In instantiation of 'bool __gnu_cxx::__ops::_Val_comp_iter<_Compare>::operator()(_Value&, _Iterator) [with _Value = long long int; _Iterator = __gnu_cxx::__normal_iterator<long long int*, std::vector<long long int> >; _Compare = main()::<lambda(auto:1&, auto:2&)>]':
/usr/include/c++/14/bits/stl_algo.h:1757:20:   requ