Problem p02758 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define maxn 100001
#define maxa 2000005
#define MOD 998244353 // 1000000007
#define INF 1000000000000000000

using namespace std;

#define ll long long
#define pii pair<ll, ll>
#define piii pair<pii, ll>
#define ft first
#define sd second
#define pb push_back
#define rep(i, n) for (ll i = 0; i < n; i++)
#define repr(i, n) for (ll i = n - 1; i >= 0; i--)
#define mem(a, b) memset(a, b, sizeof(a))
#define sort(v) sort(v.begin(), v.end())
#define edge(v, x, y)                                                          \
  v[x].pb(y);                                                                  \
  v[y].pb(x);

void fast() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout << setprecision(10) << fixed;
}
ll ceil(ll a, ll b) { return (a + b - 1) / b; }
void flaged(bool flag) {
  if (flag)
    cout << "Yes\n";
  else
    cout << "No\n";
}
// power and modulo inverse
ll power(ll a, ll b = MOD - 2) {
  if (b == 0)
    return 1;
  ll r = power(a, b / 2);
  r = (r * r) % MOD;
  if (b % 2 == 1)
    r = (r * a) % MOD;
  return r;
}
// factorial
ll fact[maxa], finv[maxa];
void calf() {
  fact[0] = finv[0] = 1;
  for (ll i = 1; i < maxa; i++) {
    fact[i] = (fact[i - 1] * i) % MOD;
    finv[i] = (finv[i - 1] * power(i)) % MOD;
  }
}
// nCr
ll ncr(ll N, ll R) {
  if (R > N)
    return 0;
  return (fact[N] * ((finv[R] * finv[N - R]) % MOD)) % MOD;
}

void solve() {
  ll n;
  cin >> n;
  vector<pii> v, vec;
  rep(i, n) {
    ll x, y;
    cin >> x >> y;
    v.pb({x, y});
  }
  sort(v);
  ll dp[n + 1];
  mem(dp, 0);
  dp[n] = 1;
  vec.pb({n, maxa});
  repr(i, n) {
    while (!vec.empty() && vec.back().sd < v[i].ft + v[i].sd) {
      vec.pop_back();
    }
    ll p = vec.back().ft;
    dp[i] = dp[p];
    vec.pb({i, v[i].ft});
    dp[i] = (dp[i] + dp[i + 1]) % MOD;
  }
  cout << dp[0];
}

int main() {
  fast();
  ll t = 1; // cin >> t;
  while (t--) {
    solve();
  }
}


Fixed submission:
#include <bits/stdc++.h>
#define maxn 100001
#define maxa 2000005
#define MOD 998244353 // 1000000007
#define INF 1000000000000000000

using namespace std;

#define ll long long
#define pii pair<ll, ll>
#define piii pair<pii, ll>
#define ft first
#define sd second
#define pb push_back
#define rep(i, n) for (ll i = 0; i < n; i++)
#define repr(i, n) for (ll i = n - 1; i >= 0; i--)
#define mem(a, b) memset(a, b, sizeof(a))
#define sort(v) sort(v.begin(), v.end())
#define edge(v, x, y)                                                          \
  v[x].pb(y);                                                                  \
  v[y].pb(x);

void fast() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout << setprecision(10) << fixed;
}
ll ceil(ll a, ll b) { return (a + b - 1) / b; }
void flaged(bool flag) {
  if (flag)
    cout << "Yes\n";
  else
    cout << "No\n";
}
// power and modulo inverse
ll power(ll a, ll b = MOD - 2) {
  if (b == 0)
    return 1;
  ll r = power(a, b / 2);
  r = (r * r) % MOD;
  if (b % 2 == 1)
    r = (r * a) % MOD;
  return r;
}
// factorial
ll fact[maxa], finv[maxa];
void calf() {
  fact[0] = finv[0] = 1;
  for (ll i = 1; i < maxa; i++) {
    fact[i] = (fact[i - 1] * i) % MOD;
    finv[i] = (finv[i - 1] * power(i)) % MOD;
  }
}
// nCr
ll ncr(ll N, ll R) {
  if (R > N)
    return 0;
  return (fact[N] * ((finv[R] * finv[N - R]) % MOD)) % MOD;
}

void solve() {
  ll n;
  cin >> n;
  vector<pii> v, vec;
  rep(i, n) {
    ll x, y;
    cin >> x >> y;
    v.pb({x, y});
  }
  sort(v);
  ll dp[n + 1];
  mem(dp, 0);
  dp[n] = 1;
  vec.pb({n, INF});
  repr(i, n) {
    while (!vec.empty() && vec.back().sd < v[i].ft + v[i].sd) {
      vec.pop_back();
    }
    ll p = vec.back().ft;
    dp[i] = dp[p];
    vec.pb({i, v[i].ft});
    dp[i] = (dp[i] + dp[i + 1]) % MOD;
  }
  cout << dp[0];
}

int main() {
  fast();
  ll t = 1; // cin >> t;
  while (t--) {
    solve();
  }
}