Language: C++

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

typedef pair<string, int> P;

bool pairCompare(const P& firstElof, const P& secondElof)
{
    return firstElof.second > secondElof.second;
}

int main() {
  int64_t N,M,Ain,B,C,min;
  vector< pair< int64_t,int64_t > > A;
  pair< int64_t,int64_t > apair;
  pair< int64_t,int64_t > bc;
  cin >> N >> M;
  min = 0;
  for (int i=0;i<N;i++ ) {
    cin >> Ain;
    apair.first = 1;
    apair.second = Ain;
    A.push_back(apair);
  }
//  for ( int64_t aa : A ) {
//	  cout << aa << " ";
//  }
//  cout << endl;
  for (int i=0; i<M; i++ ) {
    cin >> B >> C;
    apair.first = B;
    apair.second = C;
    A.push_back(apair);
  }
  sort(A.begin(),A.end(),pairCompare);

  vector<int64_t > ll;
  int tt = 0;

  for(int i=0;i<N;i++) {
    ll.push_back( A[tt].second );
    A[tt].first--;
    if (A[tt].first ==0) {
      tt++;
    }
  }
  int64_t cnt = 0;
  for ( int64_t aa : ll ) {
    cnt += aa;
  }
  cout << cnt << endl;
}
 

Compiler output:
In file included from /usr/include/c++/14/bits/stl_algobase.h:71,
                 from /usr/include/c++/14/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51,
                 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<std::pair<long int, long int>*, std::vector<std::pair<long int, long int> > >; _Iterator2 = __gnu_cxx::__normal_iterator<std::pair<long int, long int>*, std::vector<std::pair<long int, long int> > >; _Compare = bool (*)(const std::pair<std::__cxx11::basic_string<char>, int>&, const std::pair<std::__cxx11::basic_string<char>, int>&)]':
/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<pair<long int, long int>*, vector<pair<long int, long int> > >; _Compare = __gnu_cxx::__ops::_Iter_comp_iter<bool (*)(const pair<__cxx11::basic_string<char>, int>&, const pair<__cxx11::basic_string<char>, int>&)>]'
 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<pair<long int, long int>*, vector<pair<long int, long int> > >; _Compare = __gnu_cxx::__ops::_Iter_comp_iter<bool (*)(const pair<__cxx11::basic_string<char>, int>&, const pair<__cxx11::basic_string<char>, int>&)>]'
 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<pair<long int, long int>*, vector<pair<long int, long int> > >; _Compare = __gnu_cxx::__ops::_Iter_comp_iter<bool (*)(const pair<__cxx11::basic_string<char>, int>&, const pair<__cxx11::basic_string<char>, int>&)>]'
 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<pair<long int, long int>*, vector<pair<long int, long int> > >; _Compare = bool (*)(const pair<__cxx11::basic_string<char>, int>&, const pair<__cxx11::basic_string<char>, int>&)]'
 4805 |       std::__sort(__first, __last, __gnu_cxx::__ops::__iter_comp_iter(__comp));
      |       ~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:34:7:   required from here
   34 |   sort(A.begin(),A.end(),pairCompare);
      |   ~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/predefined_ops.h:158:30: error: invalid initialization of reference of type 'const std::pair<std::__cxx11::basic_string<char>, int>&' from expression of type 'std::pair<long int, long int>'
  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 = std::pair<long int, long int>; _Iterator = __gnu_cxx::__normal_iterator<std::pair<long int, long int>*, std::vector<std::pair<long int, long int> > >; _Compare = bool (*)(const std::pair<std::__cxx11::basic_string<char>, int>&, const std::pair<std::__cxx11::basic_string<char>, int>&)]':
/usr/include/c++/14/bits/stl_algo.h:1757:20:   required from 'void std::__unguarded_linear_insert(_RandomAccessIterator, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<pair<long int, long int>*, vector<pair<long int, long int> > >; _Compare = __gnu_cxx::__ops::_Val_comp_iter<bool (*)(const pair<__cxx11::basic_string<char>, int>&, const pair<__cxx11::basic_string<char>, int>&)>]'
 1757 |       while (__comp(__val, __next))
      |              ~~~~~~^~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algo.h:1785:36:   required from 'void std::__insertion_sort(_RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<pair<long int, long int>*, vector<pair<long int, long int> > >; _Compare = __gnu_cxx::__ops::_Iter_comp_iter<bool (*)(const pair<__cxx11::basic_string<char>, int>&, const pair<__cxx11::basic_string<char>, int>&)>]'
 1785 |             std::__unguarded_linear_insert(__i,
      |             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~
 1786 |                                 __gnu_cxx::__ops::__val_comp_iter(__comp));
      |                                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/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<pair<long int, long int>*, vector<pair<long int, long int> > >; _Compare = __gnu_cxx::__ops::_Iter_comp_iter<bool (*)(const pair<__cxx11::basic_string<char>, int>&, const pair<__cxx11::basic_string<char>, int>&)>]'
 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<pair<long int, long int>*, vector<pair<long int, long int> > >; _Compare = __gnu_cxx::__ops::_Iter_comp_iter<bool (*)(const pair<__cxx11::basic_string<char>, int>&, const pair<__cxx11::basic_string<char>, int>&)>]'
 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<pair<long int, long int>*, vector<pair<long int, long int> > >; _Compare = bool (*)(const pair<__cxx11::basic_string<char>, int>&, const pair<__cxx11::basic_string<char>, int>&)]'
 4805 |       std::__sort(__first, __last, __gnu_cxx::__ops::__iter_comp_iter(__comp));
      |       ~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:34:7:   required from here
   34 |   sort(A.begin(),A.end(),pairCompare);
      |   ~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/predefined_ops.h:240:30: error: invalid initialization of reference of type 'const std::pair<std::__cxx11::basic_string<char>, int>&' from expression of type 'std::pair<long int, long int>'
  240 |         { return bool(_M_comp(__val, *__it)); }
      |                       ~~~~~~~^~~~~~~~~~~~~~
/usr/include/c++/14/bits/predefined_ops.h: In instantiation of 'bool __gnu_cxx::__ops::_Iter_comp_val<_Compare>::operator()(_Iterator, _Value&) [with _Iterator = __gnu_cxx::__normal_iterator<std::pair<long int, long int>*, std::vector<std::pair<long int, long int> > >; _Value = std::pair<long int, long int>; _Compare = bool (*)(const std::pair<std::__cxx11::basic_string<char>, int>&, const std::pair<std::__cxx11::basic_string<char>, int>&)]':
/usr/include/c++/14/bits/stl_heap.h:140:48:   required from 'void std::__push_heap(_RandomAccessIterator, _Distance, _Distance, _Tp, _Compare&) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<pair<long int, long int>*, vector<pair<long int, long int> > >; _Distance = long int; _Tp = pair<long int, long int>; _Compare = __gnu_cxx::__ops::_Iter_comp_val<bool (*)(const pair<__cxx11::basic_string<char>, int>&, const pair<__cxx11::basic_string<char>, int>&)>]'
  140 |       while (__holeIndex > __topIndex && __comp(__first + __parent, __value))
      |                                          ~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_heap.h:247:23:   required from 'void std::__adjust_heap(_RandomAccessIterator, _Distance, _Distance, _Tp, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<pair<long int, long int>*, vector<pair<long int, long int> > >; _Distance = long int; _Tp = pair<long int, long int>; _Compare = __gnu_cxx::__ops::_Iter_comp_iter<bool (*)(const pair<__cxx11::basic_string<char>, int>&, const pair<__cxx11::basic_string<char>, int>&)>]'
  247 |       std::__push_heap(__first, __holeIndex, __topIndex,
      |       ~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  248 |                        _GLIBCXX_MOVE(__value), __cmp);
      |                        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_heap.h:356:22:   required from 'void std::__make_heap(_RandomAccessIterator, _RandomAccessIterator, _Compare&) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<pair<long int, long int>*, vector<pair<long int, long int> > >; _Compare = __gnu_cxx::__ops::_Iter_comp_iter<bool (*)(const pair<__cxx11::basic_string<char>, int>&, const pair<__cxx11::basic_string<char>, int>&)>]'
  356 |           std::__adjust_heap(__first, __parent, __len, _GLIBCXX_MOVE(__value),
      |           ~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  357 |                              __comp);
      |                              ~~~~~~~
/usr/include/c++/14/bits/stl_algo.h:1593:23:   required from 'void std::__heap_select(_RandomAccessIterator, _RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<pair<long int, long int>*, vector<pair<long int, long int> > >; _Compare = __gnu_cxx::__ops::_Iter_comp_iter<bool (*)(const pair<__cxx11::basic_string<char>, int>&, const pair<__cxx11::basic_string<char>, int>&)>]'
 1593 |       std::__make_heap(__first, __middle, __comp);
      |       ~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algo.h:1868:25:   required from 'vo