Language: C++

#include<iostream>
#include<queue>
using namespace std;
typedef pair<int, int> P;

int main()
{
  int N;

  cin >> N;
  priority_queue<int> que1;
  priority_queue<int, vector<int>, greater<int> > que2;
  queue<pair<int, int> > que3;

  for (int i = 0; i < N; i++)
  {
    int a;
    int max = 0; min = 0;
    cin >> a;
    if(a >= 0){
      if(a >= max) max = a;
      que1.push(a);
    }
    else{
      if(a <= min) min = a;
      que2.push(a);
    }
  }


  if(que1.size() >= 1)
  {
    max = que1.top();
    que1.pop();

    while (que1.size() >= 1)
    {
    
      if (que2.empty())
      {
        if (que1.size() == 1)
        {
          max = max - que1.top();
          P p = make_pair(max, que1.top());
          que3.push(p);
          que1.pop();
          break;
        }

        int a, b;
        a = que1.top();que1.pop();
        b = que1.top();que1.pop();
        b = b - a;
        que2.push(b);
        P p = make_pair(b, a);
        que3.push(p);
        continue;
      }

      int a, b;
      a = que2.top();que2.pop();
      b = que1.top();que1.pop();
      que2.push(a - b);
      P p = make_pair(a, b);
      que3.push(p);
      
    }

    while(!que2.empty())
    {
      int a;
      a = que2.top();
      P p = make_pair(max, que2.top());
      que3.push(p);
      max = max - a;
      que2.pop();
   }

    cout << max << endl;

    while (!que3.empty())
    {
      P p = que3.front();
      int x = p.first;
      int y = p.second;
      cout << x << ' ' << y << endl;
      que3.pop();

    }
  }
  else{
    while(!que2.empty())
    {
      int a, b;
      a = que2.top();que2.pop();
      b = que2.top();que2.pop();
      P p = make_pair(b, a);
      que3.push(p);
      max = max - a;
      que2.pop();
    }
    
  }




  return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:18:24: error: overloaded function with no contextual type information
   18 |     int max = 0; min = 0;
      |                        ^
a.cc:25:12: error: invalid operands of types 'int' and '<unresolved overloaded function type>' to binary 'operator<='
   25 |       if(a <= min) min = a;
      |          ~~^~~~~~
a.cc:25:26: error: overloaded function with no contextual type information
   25 |       if(a <= min) min = a;
      |                          ^
a.cc:33:20: error: overloaded function with no contextual type information
   33 |     max = que1.top();
      |                    ^
a.cc:43:21: error: invalid operands of types '<unresolved overloaded function type>' and 'const __gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'const int'} to binary 'operator-'
   43 |           max = max - que1.top();
      |                 ~~~~^~~~~~~~~~~~
a.cc:44:26: error: no matching function for call to 'make_pair(<unresolved overloaded function type>, const __gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type&)'
   44 |           P p = make_pair(max, que1.top());
      |                 ~~~~~~~~~^~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/bits/stl_algobase.h:64,
                 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/stl_pair.h:1132:5: note: candidate: 'template<class _T1, class _T2> constexpr std::pair<typename std::__strip_reference_wrapper<typename std::decay<_Tp>::type>::__type, typename std::__strip_reference_wrapper<typename std::decay<_Tp2>::type>::__type> std::make_pair(_T1&&, _T2&&)'
 1132 |     make_pair(_T1&& __x, _T2&& __y)
      |     ^~~~~~~~~
/usr/include/c++/14/bits/stl_pair.h:1132:5: note:   template argument deduction/substitution failed:
a.cc:44:26: note:   couldn't deduce template parameter '_T1'
   44 |           P p = make_pair(max, que1.top());
      |                 ~~~~~~~~~^~~~~~~~~~~~~~~~~
a.cc:73:22: error: no matching function for call to 'make_pair(<unresolved overloaded function type>, const __gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type&)'
   73 |       P p = make_pair(max, que2.top());
      |             ~~~~~~~~~^~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_pair.h:1132:5: note: candidate: 'template<class _T1, class _T2> constexpr std::pair<typename std::__strip_reference_wrapper<typename std::decay<_Tp>::type>::__type, typename std::__strip_reference_wrapper<typename std::decay<_Tp2>::type>::__type> std::make_pair(_T1&&, _T2&&)'
 1132 |     make_pair(_T1&& __x, _T2&& __y)
      |     ^~~~~~~~~
/usr/include/c++/14/bits/stl_pair.h:1132:5: note:   template argument deduction/substitution failed:
a.cc:73:22: note:   couldn't deduce template parameter '_T1'
   73 |       P p = make_pair(max, que2.top());
      |             ~~~~~~~~~^~~~~~~~~~~~~~~~~
a.cc:75:17: error: invalid operands of types '<unresolved overloaded function type>' and 'int' to binary 'operator-'
   75 |       max = max - a;
      |             ~~~~^~~
a.cc:79:10: error: no match for 'operator<<' (operand types are 'std::ostream' {aka 'std::basic_ostream<char>'} and '<unresolved overloaded function type>')
   79 |     cout << max << endl;
      |     ~~~~~^~~~~~
/usr/include/c++/14/ostream:116:7: note: candidate: 'std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(__ostream_type& (*)(__ostream_type&)) [with _CharT = char; _Traits = std::char_traits<char>; __ostream_type = std::basic_ostream<char>]'
  116 |       operator<<(__ostream_type& (*__pf)(__ostream_type&))
      |       ^~~~~~~~
/usr/include/c++/14/ostream:116:36: note:   no known conversion for argument 1 from '<unresolved overloaded function type>' to 'std::basic_ostream<char>::__ostream_type& (*)(std::basic_ostream<char>::__ostream_type&)' {aka 'std::basic_ostream<char>& (*)(std::basic_ostream<char>&)'}
  116 |       operator<<(__ostream_type& (*__pf)(__ostream_type&))
      |                  ~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/ostream:125:7: note: candidate: 'std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(__ios_type& (*)(__ios_type&)) [with _CharT = char; _Traits = std::char_traits<char>; __ostream_type = std::basic_ostream<char>; __ios_type = std::basic_ios<char>]'
  125 |       operator<<(__ios_type& (*__pf)(__ios_type&))
      |       ^~~~~~~~
/usr/include/c++/14/ostream:125:32: note:   no known conversion for argument 1 from '<unresolved overloaded function type>' to 'std::basic_ostream<char>::__ios_type& (*)(std::basic_ostream<char>::__ios_type&)' {aka 'std::basic_ios<char>& (*)(std::basic_ios<char>&)'}
  125 |       operator<<(__ios_type& (*__pf)(__ios_type&))
      |                  ~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~
/usr/include/c++/14/ostream:135:7: note: candidate: 'std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(std::ios_base& (*)(std::ios_base&)) [with _CharT = char; _Traits = std::char_traits<char>; __ostream_type = std::basic_ostream<char>]'
  135 |       operator<<(ios_base& (*__pf) (ios_base&))
      |       ^~~~~~~~
/usr/include/c++/14/ostream:135:30: note:   no known conversion for argument 1 from '<unresolved overloaded function type>' to 'std::ios_base& (*)(std::ios_base&)'
  135 |       operator<<(ios_base& (*__pf) (ios_base&))
      |                  ~~~~~~~~~~~~^~~~~~~~~~~~~~~~~
/usr/include/c++/14/ostream:174:7: note: candidate: 'std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(long int) [with _CharT = char; _Traits = std::char_traits<char>; __ostream_type = std::basic_ostream<char>]'
  174 |       operator<<(long __n)
      |       ^~~~~~~~
/usr/include/c++/14/ostream:174:23: note:   no known conversion for argument 1 from '<unresolved overloaded function type>' to 'long int'
  174 |       operator<<(long __n)
      |                  ~~~~~^~~
/usr/include/c++/14/ostream:178:7: note: candidate: 'std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(long unsigned int) [with _CharT = char; _Traits = std::char_traits<char>; __ostream_type = std::basic_ostream<char>]'
  178 |       operator<<(unsigned long __n)
      |       ^~~~~~~~
/usr/include/c++/14/ostream:178:32: note:   no known conversion for argument 1 from '<unresolved overloaded function type>' to 'long unsigned int'
  178 |       operator<<(unsigned long __n)
      |                  ~~~~~~~~~~~~~~^~~
/usr/include/c++/14/ostream:182:7: note: candidate: 'std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(bool) [with _CharT = char; _Traits = std::char_traits<char>; __ostream_type = std::basic_ostream<char>]'
  182 |       operator<<(bool __n)
      |       ^~~~~~~~
/usr/include/c++/14/ostream:182:23: note:   no known conversion for argument 1 from '<unresolved overloaded function type>' to 'bool'
  182 |       operator<<(bool __n)
      |                  ~~~~~^~~
In file included from /usr/include/c++/14/ostream:1022:
/usr/include/c++/14/bits/ostream.tcc:96:5: note: candidate: 'std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(short int) [with _CharT = char; _Traits = std::char_traits<char>]'
   96 |     basic_ostream<_CharT, _Traits>::
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/ostream.tcc:97:22: note:   no known conversion for argument 1 from '<unresolved overloaded function type>' to 'short int'
   97 |     operator<<(short __n)
      |                ~~~~~~^~~
/usr/include/c++/14/ostream:189:7: note: candidate: 'std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(short unsigned int) [with _CharT = char; _Traits = std::char_traits<char>; __ostream_type = std::basic_ostream<char>]'
  189 |       operator<<(unsigned short __n)
      |       ^~~~~~~~
/usr/include/c++/14/ostream:189:33: note:   no known conversion for argument 1 from '<unresolved overloaded function type>' to 'short unsigned int'
  189 |       operator<<(unsigned short __n)
      |                  ~~~~~~~~~~~~~~~^~~
/usr/include/c++/14/bits/ostream.tcc:110:5: note: candidate: 'std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(int) [with _CharT = char; _Traits = std::char_traits<char>]'
  110 |     basic_ostream<_CharT, _Traits>::
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/ostream.tcc:111:20: note:   no known conversion for argument 1 from '<unresolved overloaded function type>' to 'int'
  111 |     operator<<(int __n)
      |                ~~~~^~~
/usr/include/c++/14/ostream:200:7: note: candidate: 'std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(unsigned int) [with _CharT = char; _Traits = std::char_traits<char>; __ostream_type = std::basic_ostream<char>]'
  200 |       operator<<(unsigned int __n)
      |       ^~~~~~~~
/usr/include/c++/14/ostream:200:31: note:   no known conversion for argument 1 from '<unresolved overloaded function type>' to 'unsigned int'
  200 |       operator<<(unsigned int __n)
      |                  ~~~~~~~~~~~~~^~~
/usr/include/c++/14/ostream:211:7: note: candidate: 'std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(long long int) [with _CharT = char; _Traits = std::char_traits<char>; __ostream_type = std::basic_ostream<char>]'
  211 |       operator<<(long long __n)
      |       ^~~~~~~~
/usr/include/c++/14/ostream:211:28: note:   no known conversion for argument 1 from '<unresolved overloaded function type>' to 'long long int'
  211 |       operator<<(long long __n)
      |                  ~~~~~~~~~~^~~
/usr/include/c++/14/ostream:215:7: note: candidate: 'std::basic_ostream<_Ch