Problem p02948 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
typedef long long int ll;
typedef long double ld;
#define sync                                                                   \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(NULL)
#define input(arr, n)                                                          \
  for (ll i1 = 0; i1 < n; i1++)                                                \
  cin >> arr[i1]
#define pb(x) push_back(x)
#define si(a) scanf("%lld", &a)
#define pi(a) printf("%lld", a)
#define mod 1000000007
#define f first
#define s second
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
// #pragma GCC optimize("O3")
 // recursions\
#pragma comment(linker, "/stack:200000000")
// loops
#pragma GCC optimize("unroll-loops")
using namespace __gnu_pbds;
#define ordered_set                                                            \
  tree<ll, null_type, greater_equal<ll>, rb_tree_tag,                          \
       tree_order_statistics_node_update> // s.order_of_key(val)
                                          // *s.find_by_order(ind)
using namespace std;
int main() {
  sync;
  ll n, m;
  cin >> n >> m;
  multiset<pair<ll, ll>> ms;
  set<ll> days;
  for (ll i = 0; i < n; i++) {
    ll x, y;
    cin >> x >> y;
    if (x <= m) {
      ms.insert({y, -x});
    }
  }
  for (ll i = 1; i <= m; i++)
    days.insert(i);
  ll ans = 0;
  multiset<pair<ll, ll>>::iterator it;
  set<ll>::iterator day;
  while (days.size() > 0 && ms.size() > 0) {
    it = ms.end();
    it--;
    ll val = -(it->second);
    day = lower_bound(days.begin(), days.end(), val);
    if (day != days.end()) {
      ans += it->first;
      days.erase(day);
    }
    ms.erase(it);
  }
  cout << ans;
}


Fixed submission:
#include <bits/stdc++.h>
typedef long long int ll;
typedef long double ld;
#define sync                                                                   \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(NULL)
#define input(arr, n)                                                          \
  for (ll i1 = 0; i1 < n; i1++)                                                \
  cin >> arr[i1]
#define pb(x) push_back(x)
#define si(a) scanf("%lld", &a)
#define pi(a) printf("%lld", a)
#define mod 1000000007
#define f first
#define s second
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
// #pragma GCC optimize("O3")
 // recursions\
#pragma comment(linker, "/stack:200000000")
// loops
#pragma GCC optimize("unroll-loops")
using namespace __gnu_pbds;
#define ordered_set                                                            \
  tree<ll, null_type, greater_equal<ll>, rb_tree_tag,                          \
       tree_order_statistics_node_update> // s.order_of_key(val)
                                          // *s.find_by_order(ind)
using namespace std;
int main() {
  sync;
  ll n, m;
  cin >> n >> m;
  multiset<pair<ll, ll>> ms;
  set<ll> days;
  for (ll i = 0; i < n; i++) {
    ll x, y;
    cin >> x >> y;
    if (x <= m) {
      ms.insert({y, -x});
    }
  }
  for (ll i = 1; i <= m; i++)
    days.insert(i);
  ll ans = 0;
  multiset<pair<ll, ll>>::iterator it;
  set<ll>::iterator day;
  while (days.size() > 0 && ms.size() > 0) {
    it = ms.end();
    it--;
    ll val = -(it->second);
    day = days.lower_bound(val);
    if (day != days.end()) {
      ans += it->first;
      days.erase(day);
    }
    ms.erase(it);
  }
  cout << ans;
}