Language: C++

#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define pb push_back
#define ins insert
#define all(x) (x).begin(),(x).end()
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[8]={1,0,-1,0,1,1,-1,-1};
const ll dx[8]={0,-1,0,1,1,-1,1,-1};
using Graph = vector<vector<int>>;
double nCk(int n, int k) {
double res=1.0;
for(int i=0; i<n; i++){
res*=0.5;}
for(int i=0; i<k; i++){
res*=(double)(n-i);
res/=(double)(k-i);
}
return res;}
struct edge{ll to, cost;};
typedef pair<ll,ll> P;
struct graph{
  ll V;
  vector<vector<edge> > G;
  vector<ll> d;

  graph(ll n){
    init(n);
  }

  void init(ll n){
    V = n;
    G.resize(V);
    d.resize(V);
    rep(i,V){
      d[i] = INF;
    }
  }

  void add_edge(ll s, ll t, ll cost){
    edge e;
    e.to = t, e.cost = cost;
    G[s].push_back(e);
  }

  void dijkstra(ll s){
    rep(i,V){
      d[i] = INF;
    }
    d[s] = 0;
    priority_queue<P,vector<P>, greater<P> > que;
    que.push(P(0,s));
    while(!que.empty()){
      P p = que.top(); que.pop();
      ll v = p.second;
      if(d[v]<p.first) continue;
      for(auto e : G[v]){
        if(d[e.to]>d[v]+e.cost){
          d[e.to] = d[v]+e.cost;
          que.push(P(d[e.to],e.to));
        }
      }
    }
  }
};
class UnionFind
{
public:
  int par[100005];
  int depth[100005];
  int nGroup[100005];
 
  UnionFind(int n) {
    init(n);
  }
 
  void init(int n) {
    for(int i=0; i<n; i++) {
      par[i] = i;
      depth[i] = 0;
      nGroup[i] = 1;
    }
  }
 
  int root(int x) {
    if(par[x] == x) {
      return x;
    } else {
      return par[x] = root(par[x]);
    }
  }
 
  bool same(int x, int y) {
    return root(x) == root(y);
  }
 
  void unite(int x, int y) {
    x = root(x);
    y = root(y);
    if(x == y) return;
 
    if(depth[x] < depth[y]) {
      par[x] = y;
      nGroup[y] += nGroup[x];
      nGroup[x] = 0;
    } else {
      par[y] = x;
      nGroup[x] += nGroup[y];
      nGroup[y] = 0;
      if(depth[x] == depth[y])
        depth[x]++;
    }
  }
};
const ll MAX = 510000;
ll fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
ll COM(ll n, ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
} 
int main() {
ll n,k; cin>>n>>k;
multimap<ll,ll> mp;
rep(i,n){
ll r,l;
cin>>r>>l;
mp.insert(r,l);}
ll ans = 0;
priority_queue<ll> a;
ll b = 0;
repl(i,1,k){
if(!mp.count(i))continue;
for(auto p : mp){
a.push(p.se);}
if(!a.empty()){
ans += a.top();
a.pop();}
}
cout << ans << endl;}


Compiler output:
In file included from /usr/include/c++/14/map:64,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:152,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_multimap.h: In instantiation of 'void std::multimap<_Key, _Tp, _Compare, _Alloc>::insert(_InputIterator, _InputIterator) [with _InputIterator = long long int; _Key = long long int; _Tp = long long int; _Compare = std::less<long long int>; _Alloc = std::allocator<std::pair<const long long int, long long int> >]':
a.cc:153:10:   required from here
  153 | mp.insert(r,l);}
      | ~~~~~~~~~^~~~~
/usr/include/c++/14/bits/stl_multimap.h:620:37: error: no matching function for call to 'std::_Rb_tree<long long int, std::pair<const long long int, long long int>, std::_Select1st<std::pair<const long long int, long long int> >, std::less<long long int>, std::allocator<std::pair<const long long int, long long int> > >::_M_insert_range_equal(long long int&, long long int&)'
  620 |         { _M_t._M_insert_range_equal(__first, __last); }
      |           ~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/map:62:
/usr/include/c++/14/bits/stl_tree.h:1113:9: note: candidate: 'template<class _InputIterator> std::__enable_if_t<((bool)std::is_same<_Val, typename std::iterator_traits<_InputIterator>::value_type>::value)> std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::_M_insert_range_equal(_InputIterator, _InputIterator) [with _Key = long long int; _Val = std::pair<const long long int, long long int>; _KeyOfValue = std::_Select1st<std::pair<const long long int, long long int> >; _Compare = std::less<long long int>; _Alloc = std::allocator<std::pair<const long long int, long long int> >]'
 1113 |         _M_insert_range_equal(_InputIterator __first, _InputIterator __last)
      |         ^~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_tree.h:1113:9: note:   template argument deduction/substitution failed:
/usr/include/c++/14/bits/stl_tree.h: In substitution of 'template<class _InputIterator> std::__enable_if_t<((bool)std::is_same<std::pair<const long long int, long long int>, typename std::iterator_traits< <template-parameter-1-1> >::value_type>::value), void> std::_Rb_tree<long long int, std::pair<const long long int, long long int>, std::_Select1st<std::pair<const long long int, long long int> >, std::less<long long int>, std::allocator<std::pair<const long long int, long long int> > >::_M_insert_range_equal(_InputIterator, _InputIterator) [with _InputIterator = long long int]':
/usr/include/c++/14/bits/stl_multimap.h:620:30:   required from 'void std::multimap<_Key, _Tp, _Compare, _Alloc>::insert(_InputIterator, _InputIterator) [with _InputIterator = long long int; _Key = long long int; _Tp = long long int; _Compare = std::less<long long int>; _Alloc = std::allocator<std::pair<const long long int, long long int> >]'
  620 |         { _M_t._M_insert_range_equal(__first, __last); }
      |           ~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~
a.cc:153:10:   required from here
  153 | mp.insert(r,l);}
      | ~~~~~~~~~^~~~~
/usr/include/c++/14/bits/stl_tree.h:1095:58: error: no type named 'value_type' in 'struct std::iterator_traits<long long int>'
 1095 |         __enable_if_t<__same_value_type<_InputIterator>::value>
      |                                                          ^~~~~
/usr/include/c++/14/bits/stl_multimap.h: In instantiation of 'void std::multimap<_Key, _Tp, _Compare, _Alloc>::insert(_InputIterator, _InputIterator) [with _InputIterator = long long int; _Key = long long int; _Tp = long long int; _Compare = std::less<long long int>; _Alloc = std::allocator<std::pair<const long long int, long long int> >]':
a.cc:153:10:   required from here
  153 | mp.insert(r,l);}
      | ~~~~~~~~~^~~~~
/usr/include/c++/14/bits/stl_tree.h:1122:9: note: candidate: 'template<class _InputIterator> std::__enable_if_t<((bool)(! std::is_same<_Val, typename std::iterator_traits<_InputIterator>::value_type>::value))> std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::_M_insert_range_equal(_InputIterator, _InputIterator) [with _Key = long long int; _Val = std::pair<const long long int, long long int>; _KeyOfValue = std::_Select1st<std::pair<const long long int, long long int> >; _Compare = std::less<long long int>; _Alloc = std::allocator<std::pair<const long long int, long long int> >]'
 1122 |         _M_insert_range_equal(_InputIterator __first, _InputIterator __last)
      |         ^~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_tree.h:1122:9: note:   template argument deduction/substitution failed:
/usr/include/c++/14/bits/stl_tree.h: In substitution of 'template<class _InputIterator> std::__enable_if_t<((bool)(! std::is_same<std::pair<const long long int, long long int>, typename std::iterator_traits< <template-parameter-1-1> >::value_type>::value)), void> std::_Rb_tree<long long int, std::pair<const long long int, long long int>, std::_Select1st<std::pair<const long long int, long long int> >, std::less<long long int>, std::allocator<std::pair<const long long int, long long int> > >::_M_insert_range_equal(_InputIterator, _InputIterator) [with _InputIterator = long long int]':
/usr/include/c++/14/bits/stl_multimap.h:620:30:   required from 'void std::multimap<_Key, _Tp, _Compare, _Alloc>::insert(_InputIterator, _InputIterator) [with _InputIterator = long long int; _Key = long long int; _Tp = long long int; _Compare = std::less<long long int>; _Alloc = std::allocator<std::pair<const long long int, long long int> >]'
  620 |         { _M_t._M_insert_range_equal(__first, __last); }
      |           ~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~
a.cc:153:10:   required from here
  153 | mp.insert(r,l);}
      | ~~~~~~~~~^~~~~
/usr/include/c++/14/bits/stl_tree.h:1104:59: error: no type named 'value_type' in 'struct std::iterator_traits<long long int>'
 1104 |         __enable_if_t<!__same_value_type<_InputIterator>::value>
      |                                                           ^~~~~