Language: C++

//#pragma GCC optimize("O3", "unroll-loops")
//#pragma GCC target("avx2")
#include<bits/stdc++.h>

#define FAST ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define FIXED cout << fixed << setprecision(12)
#define RANDOM srand(94385)
#define all(a) a.begin(), a.end()
#define shuffle(a) \
    for (int i = 0; i < sz(a); ++i) \
        swap(a[i], a[rand() % sz(a)]);
#define enter puts("")
#define space putchar(' ')
#define Mem(a, x) memset(a, x, sizeof(a))
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;

void debug_out() { cerr << '\n'; }

template<typename T, typename ...R>
void debug_out(const T &f, const R &...r) {
    cerr << f << " ";
    debug_out(r...);
}

#define debug(...) cerr << "[" << #__VA_ARGS__ << "]: ", debug_out(__VA_ARGS__);

inline ll read() {
    ll x = 0;
    int f = 0;
    char ch = getchar();
    while (ch < '0' || ch > '9') f |= (ch == '-'), ch = getchar();
    while (ch >= '0' && ch <= '9') x = (x << 3) + (x << 1) + ch - '0', ch = getchar();
    return x = f ? -x : x;
}

inline void write(ll x) {
    if (x == 0) {
        putchar('0');
        return;
    }
    if (x < 0) {
        putchar('-');
        x = -x;
    }
    static char s[23];
    int l = 0;
    while (x != 0)s[l++] = x % 10 + 48, x /= 10;
    while (l)putchar(s[--l]);
}

int lowbit(int x) { return x & (-x); }

template<class T>
T big(const T &a1, const T &a2) { return a1 > a2 ? a1 : a2; }

template<typename T, typename ...R>
T big(const T &f, const R &...r) { return big(f, big(r...)); }

template<class T>
T sml(const T &a1, const T &a2) { return a1 < a2 ? a1 : a2; }

template<typename T, typename ...R>
T sml(const T &f, const R &...r) { return sml(f, sml(r...)); }

template<class T, class U>
inline void checkMin(T &x, U y) { if (y < x) x = y; }

template<class T, class U>
inline void checkMax(T &x, U y) { if (y > x) x = y; }

template<class T, class U>
inline bool ifMax(T &x, U y) {
    if (y > x) return x = y, true;
    return false;
}

template<class T, class U>
inline bool ifMin(T &x, U y) {
    if (y < x) return x = y, true;
    return false;
}

const int M = 212345;// 2e5+5
const int inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const int mod = 1000000007;// 1e9+7

// HAVE FREE OPEN IN MAIN FUNCTION



int n, m;

struct node {
    ll sum;
    int ll, rr;
} tree[M * 4];

void build(int rt, int l, int r) {
    tree[rt].ll = l, tree[rt].rr = r;
    if (l == r) {
        tree[rt].sum = 1;
        return;
    }
    int mid = (l + r) / 2;
    build(rt * 2, l, mid);
    build(rt * 2 + 1, mid + 1, r);
    tree[rt].sum = tree[rt * 2].sum + tree[rt * 2 + 1].sum;
}

struct node2 {
    ll a, b;
} v[M];

bool cmp(node2 x, node2 y) {
    return x.b > y.b;
}

int query(int rt, int l, int r, int qL, int qR) {
    if (l == r) {
        if (tree[rt].sum != 0)return l;
        else return -1;
    }
    int mid = (l + r) / 2;
    int flag=0;
    if (qR > mid && tree[rt * 2 + 1].sum != 0)flag=query(rt * 2 + 1, mid + 1, r, qL, qR);
    if(flag!=-1&&flag!=0)return flag;
    else return query(rt * 2, l, mid, qL, qR);

}

void update(int rt, int l, int r, int pos) {
    if (l == r) {
        tree[rt].sum = 0;
        return;
    }
    int mid = (l + r) / 2;
    if (pos <= mid)update(rt * 2, l, mid, pos);
    else update(rt * 2 + 1, mid + 1, r, pos);
    tree[rt].sum = tree[rt * 2].sum + tree[rt * 2 + 1].sum;
}

void init() {
    n = read(), m = read();
    m++;
    for (int i = 1; i <= n; ++i) {
        v[i].a = read();
        v[i].a = m - v[i].a;
        v[i].b = read();
    }
    build(1, 1, m);
    sort(v + 1, v + 1 + n, cmp);
//    for (int i = 1; i <= n; ++i) {
//        printf("%lld %lld\n", v[i].a, v[i].b);
//    }
    ll ans = 0;
    for (int i = 1; i <= n; ++i) {
        int pos = query(1, 1, m, 1, v[i].a);
//        debug(v[i].a, pos);
        if (pos != -1) {
            ans += v[i].b;
            update(1, 1, m, pos);
        }
    }
    write(ans);
    enter;
}

void solve() {

}

int main() {
    init();

    solve();

    return 0;
}

Compiler output:
a.cc:99:9: error: declaration of 'int node::ll' changes meaning of 'll' [-Wchanges-meaning]
   99 |     int ll, rr;
      |         ^~
a.cc:98:5: note: used here to mean 'typedef long long int ll'
   98 |     ll sum;
      |     ^~
a.cc:17:19: note: declared here
   17 | typedef long long ll;
      |                   ^~