Language: C++

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

using namespace std;

int main(){
  int n, m;
  cin >> n >> m;
  vector<vector<int> > v(n);

  int a, b;
  for(int i = 0; i < n; ++i){
    cin >> a >> b;
    v[a - 1].push_back(b);
  }

  long long res = 0;

  for(int i = 0; i < n; ++i){
    int max = 0;
    int max_vec;
    size_t max_index;
    for(int j = 0; j <= i; ++j){
      iterator iter = max_element(v[i].begin(), v[i].end());
      if(max < *iter){
        max = *iter;
        max_vec = j;
        max_index = distance(v[j].begin(), iter);
      }
    }
    res += max;
    v[max_vec].erase(max_index);
  }

  cout << res << endl;
  return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:26:59: error: class template argument deduction failed:
   26 |       iterator iter = max_element(v[i].begin(), v[i].end());
      |                                                           ^
a.cc:26:59: error: no matching function for call to 'iterator(__gnu_cxx::__normal_iterator<int*, std::vector<int> >)'
In file included from /usr/include/c++/14/bits/stl_iterator_base_funcs.h:66,
                 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_types.h:127:34: note: candidate: 'template<class _Category, class _Tp, class _Distance, class _Pointer, class _Reference> iterator()-> std::iterator<_Category, _Tp, _Distance, _Pointer, _Reference>'
  127 |     struct _GLIBCXX17_DEPRECATED iterator
      |                                  ^~~~~~~~
/usr/include/c++/14/bits/stl_iterator_base_types.h:127:34: note:   candidate expects 0 arguments, 1 provided
/usr/include/c++/14/bits/stl_iterator_base_types.h:127:34: note: candidate: 'template<class _Category, class _Tp, class _Distance, class _Pointer, class _Reference> iterator(std::iterator<_Category, _Tp, _Distance, _Pointer, _Reference>)-> std::iterator<_Category, _Tp, _Distance, _Pointer, _Reference>'
/usr/include/c++/14/bits/stl_iterator_base_types.h:127:34: note:   template argument deduction/substitution failed:
a.cc:26:59: note:   '__gnu_cxx::__normal_iterator<int*, std::vector<int> >' is not derived from 'std::iterator<_Category, _Tp, _Distance, _Pointer, _Reference>'
   26 |       iterator iter = max_element(v[i].begin(), v[i].end());
      |                                                           ^
a.cc:34:21: error: no matching function for call to 'std::vector<int>::erase(size_t&)'
   34 |     v[max_vec].erase(max_index);
      |     ~~~~~~~~~~~~~~~~^~~~~~~~~~~
In file included from /usr/include/c++/14/vector:66,
                 from a.cc:3:
/usr/include/c++/14/bits/stl_vector.h:1536:7: note: candidate: 'std::vector<_Tp, _Alloc>::iterator std::vector<_Tp, _Alloc>::erase(const_iterator) [with _Tp = int; _Alloc = std::allocator<int>; iterator = std::vector<int>::iterator; const_iterator = std::vector<int>::const_iterator]'
 1536 |       erase(const_iterator __position)
      |       ^~~~~
/usr/include/c++/14/bits/stl_vector.h:1536:28: note:   no known conversion for argument 1 from 'size_t' {aka 'long unsigned int'} to 'std::vector<int>::const_iterator'
 1536 |       erase(const_iterator __position)
      |             ~~~~~~~~~~~~~~~^~~~~~~~~~
/usr/include/c++/14/bits/stl_vector.h:1564:7: note: candidate: 'std::vector<_Tp, _Alloc>::iterator std::vector<_Tp, _Alloc>::erase(const_iterator, const_iterator) [with _Tp = int; _Alloc = std::allocator<int>; iterator = std::vector<int>::iterator; const_iterator = std::vector<int>::const_iterator]'
 1564 |       erase(const_iterator __first, const_iterator __last)
      |       ^~~~~
/usr/include/c++/14/bits/stl_vector.h:1564:7: note:   candidate expects 2 arguments, 1 provided