Language: C++

#include <iostream>
#include <algorithm>
#include <stdlib.h>
#include <vector>

using namespace std;

int N,i,j,k,A_point = 0,B_point = 0,index_A_max,index_B_max_in_A,index_B_max,index_A_max_in_B,B_reshaped,A_reshaped;
int* A_max,B_max_in_A,B_max,A_max_in_B;
int main() {
    cin >> N;
    int A[100000],B[100000];
    for (int i = 0; i < N; ++i) cin >> A[i] >> B[i];
    for (int i = 0; i < N; ++i){
        A_max = std::max_element(A, A+N);
        index_A_max = std::distance(A, A_max);
        B_reshaped = B[index_A_max];
        B_max_in_A = std::max_element(B_reshaped, B_reshaped + N);
        index_B_max_in_A = std::distance(B, B_max_in_A)[0];
        A_point += A[index_B_max_in_A];
        A[index_B_max_in_A] == 0;
        B[index_B_max_in_A] == 0;

        B_max = std::max_element(B, B+N);
        index_B_max = std::distance(B, B_max);
        A_reshaped = A[index_B_max];
        A_max_in_B = std::max_element(A_reshaped, A_reshaped + N);
        index_A_max_in_B = std::distance(A, A_max_in_B)[0];
        B_point += B[index_A_max_in_B];
        A[index_A_max_in_B] == 0;
        B[index_A_max_in_B] == 0;
    }
    cout << A_point - B_point << endl;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:19:41: error: no matching function for call to 'distance(int [100000], int&)'
   19 |         index_B_max_in_A = std::distance(B, B_max_in_A)[0];
      |                            ~~~~~~~~~~~~~^~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/string:47,
                 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/stl_iterator_base_funcs.h:148:5: note: candidate: 'template<class _InputIterator> constexpr typename std::iterator_traits< <template-parameter-1-1> >::difference_type std::distance(_InputIterator, _InputIterator)'
  148 |     distance(_InputIterator __first, _InputIterator __last)
      |     ^~~~~~~~
/usr/include/c++/14/bits/stl_iterator_base_funcs.h:148:5: note:   template argument deduction/substitution failed:
a.cc:19:41: note:   deduced conflicting types for parameter '_InputIterator' ('int*' and 'int')
   19 |         index_B_max_in_A = std::distance(B, B_max_in_A)[0];
      |                            ~~~~~~~~~~~~~^~~~~~~~~~~~~~~
a.cc:24:33: error: invalid conversion from 'int*' to 'int' [-fpermissive]
   24 |         B_max = std::max_element(B, B+N);
      |                 ~~~~~~~~~~~~~~~~^~~~~~~~
      |                                 |
      |                                 int*
a.cc:25:36: error: no matching function for call to 'distance(int [100000], int&)'
   25 |         index_B_max = std::distance(B, B_max);
      |                       ~~~~~~~~~~~~~^~~~~~~~~~
/usr/include/c++/14/bits/stl_iterator_base_funcs.h:148:5: note: candidate: 'template<class _InputIterator> constexpr typename std::iterator_traits< <template-parameter-1-1> >::difference_type std::distance(_InputIterator, _InputIterator)'
  148 |     distance(_InputIterator __first, _InputIterator __last)
      |     ^~~~~~~~
/usr/include/c++/14/bits/stl_iterator_base_funcs.h:148:5: note:   template argument deduction/substitution failed:
a.cc:25:36: note:   deduced conflicting types for parameter '_InputIterator' ('int*' and 'int')
   25 |         index_B_max = std::distance(B, B_max);
      |                       ~~~~~~~~~~~~~^~~~~~~~~~
a.cc:28:41: error: no matching function for call to 'distance(int [100000], int&)'
   28 |         index_A_max_in_B = std::distance(A, A_max_in_B)[0];
      |                            ~~~~~~~~~~~~~^~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_iterator_base_funcs.h:148:5: note: candidate: 'template<class _InputIterator> constexpr typename std::iterator_traits< <template-parameter-1-1> >::difference_type std::distance(_InputIterator, _InputIterator)'
  148 |     distance(_InputIterator __first, _InputIterator __last)
      |     ^~~~~~~~
/usr/include/c++/14/bits/stl_iterator_base_funcs.h:148:5: note:   template argument deduction/substitution failed:
a.cc:28:41: note:   deduced conflicting types for parameter '_InputIterator' ('int*' and 'int')
   28 |         index_A_max_in_B = std::distance(A, A_max_in_B)[0];
      |                            ~~~~~~~~~~~~~^~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/bits/stl_algobase.h:71,
                 from /usr/include/c++/14/string:51:
/usr/include/c++/14/bits/predefined_ops.h: In instantiation of 'constexpr bool __gnu_cxx::__ops::_Iter_less_iter::operator()(_Iterator1, _Iterator2) const [with _Iterator1 = int; _Iterator2 = int]':
/usr/include/c++/14/bits/stl_algo.h:5626:12:   required from 'constexpr _ForwardIterator std::__max_element(_ForwardIterator, _ForwardIterator, _Compare) [with _ForwardIterator = int; _Compare = __gnu_cxx::__ops::_Iter_less_iter]'
 5626 |         if (__comp(__result, __first))
      |             ~~~~~~^~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algo.h:5650:43:   required from 'constexpr _FIter std::max_element(_FIter, _FIter) [with _FIter = int]'
 5650 |       return _GLIBCXX_STD_A::__max_element(__first, __last,
      |                                           ^
a.cc:18:38:   required from here
   18 |         B_max_in_A = std::max_element(B_reshaped, B_reshaped + N);
      |                      ~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/predefined_ops.h:45:16: error: invalid type argument of unary '*' (have 'int')
   45 |       { return *__it1 < *__it2; }
      |                ^~~~~~
/usr/include/c++/14/bits/predefined_ops.h:45:25: error: invalid type argument of unary '*' (have 'int')
   45 |       { return *__it1 < *__it2; }
      |                         ^~~~~~