Language: C++

#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
using namespace std;

using pii = pair<int, int>;

int main(){
    int N, M;
    cin >> N >> M;
    
    vector<pii> AB(N);
    for(int i = 0; i < N; ++i){
        cin >> AB[i].first >> AB[i].second;
    }

    sort(begin(AB), end(AB));

    priority_queue<pii, vector<pii>, function<bool(pii, pii)>> q(
        [](pair<int, int> a, pair<int, int> b){
            return (a.second == b.second) ? (a.first > b.first) : (a.second < b.second);
        }
    );

    int d = 1;
    int j = 0;
    for(int i = 0; i < N; ++i){
        if(AB[i].first != d){
            break;
        }else{
            q.emplace(AB[i]);
            ++j;
        }
    }

    int ans = 0;
    while(d <= M){
        if(!q.empty()){
            ans += q.top().second;
            q.pop();
        }
        
        ++d;
        for(int i = j; i < N; ++i){
            if(AB[i].first != d){
                break;
            }else{
                q.emplace(AB[i]);
                ++j;
            }
        }
    }

    cout << ans << endl;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:20:38: error: 'function' was not declared in this scope
   20 |     priority_queue<pii, vector<pii>, function<bool(pii, pii)>> q(
      |                                      ^~~~~~~~
a.cc:5:1: note: 'std::function' is defined in header '<functional>'; this is probably fixable by adding '#include <functional>'
    4 | #include <algorithm>
  +++ |+#include <functional>
    5 | using namespace std;
a.cc:20:60: error: expression list treated as compound expression in functional cast [-fpermissive]
   20 |     priority_queue<pii, vector<pii>, function<bool(pii, pii)>> q(
      |                                                            ^
a.cc:20:61: error: template argument 3 is invalid
   20 |     priority_queue<pii, vector<pii>, function<bool(pii, pii)>> q(
      |                                                             ^~
a.cc:21:9: error: invalid user-defined conversion from 'main()::<lambda(std::pair<int, int>, std::pair<int, int>)>' to 'int' [-fpermissive]
   21 |         [](pair<int, int> a, pair<int, int> b){
      |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   22 |             return (a.second == b.second) ? (a.first > b.first) : (a.second < b.second);
      |             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   23 |         }
      |         ~
a.cc:21:9: note: candidate is: 'constexpr main()::<lambda(std::pair<int, int>, std::pair<int, int>)>::operator bool (*)(std::pair<int, int>, std::pair<int, int>)() const' (near match)
   21 |         [](pair<int, int> a, pair<int, int> b){
      |         ^
a.cc:21:9: note:   no known conversion from 'bool (*)(std::pair<int, int>, std::pair<int, int>)' to 'int'
a.cc:32:15: error: request for member 'emplace' in 'q', which is of non-class type 'int'
   32 |             q.emplace(AB[i]);
      |               ^~~~~~~
a.cc:39:15: error: request for member 'empty' in 'q', which is of non-class type 'int'
   39 |         if(!q.empty()){
      |               ^~~~~
a.cc:40:22: error: request for member 'top' in 'q', which is of non-class type 'int'
   40 |             ans += q.top().second;
      |                      ^~~
a.cc:41:15: error: request for member 'pop' in 'q', which is of non-class type 'int'
   41 |             q.pop();
      |               ^~~
a.cc:49:19: error: request for member 'emplace' in 'q', which is of non-class type 'int'
   49 |                 q.emplace(AB[i]);
      |                   ^~~~~~~