Problem p02549 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, from, to) for (ll i = from; i < (to); ++i)
#define mp(x, y) make_pair(x, y)
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
#define pb push_back
using ll = long long;
using ld = long double;
using vin = vector<int>;
using vvin = vector<vin>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vst = vector<string>;
using P = pair<ll, ll>;
const int inf = 998244353;
const ll INF = 9e18;
const long double PI = acos(-1.0);
template <typename T> bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <typename T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline void Yes(T condition) {
  if (condition)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}
template <class T> inline void YES(T condition) {
  if (condition)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
}
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

ll dp[220000];

int main() {
  cout << fixed << setprecision(20);
  ll n, k;
  cin >> n >> k;
  vll l(k), r(k);
  rep(i, 0, k) cin >> l[i] >> r[i];
  // dp,imos
  dp[1] = 1;
  dp[2] = -1;
  rep(i, 1, n + 1) {
    dp[i] = (dp[i] + dp[i - 1]) % inf;
    rep(j, 0, k) {
      if (i + l[j] < n + 2)
        dp[i + l[j]] = (dp[i + l[j]] + dp[i]) % inf;
      if (i + r[j] + 1 < n + 2)
        dp[i + r[j] + 1] = (dp[i + r[j] + 1] - dp[i]) % inf;
    }
  }
  if (dp[n] < 0)
    dp[n] += inf;
  cout << dp[n] << endl;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, from, to) for (ll i = from; i < (to); ++i)
#define mp(x, y) make_pair(x, y)
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
#define pb push_back
using ll = long long;
using ld = long double;
using vin = vector<int>;
using vvin = vector<vin>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vst = vector<string>;
using P = pair<ll, ll>;
const int inf = 998244353;
const ll INF = 9e18;
const long double PI = acos(-1.0);
template <typename T> bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <typename T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline void Yes(T condition) {
  if (condition)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}
template <class T> inline void YES(T condition) {
  if (condition)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
}
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

ll dp[220000];

int main() {
  cout << fixed << setprecision(20);
  ll n, k;
  cin >> n >> k;
  vll l(k), r(k);
  rep(i, 0, k) cin >> l[i] >> r[i];
  // dp,imos
  dp[1] = 1;
  dp[2] = -1;
  rep(i, 1, n + 1) {
    dp[i] = (dp[i] + dp[i - 1]) % inf;
    rep(j, 0, k) {
      dp[i + l[j]] = (dp[i + l[j]] + dp[i]) % inf;
      dp[i + r[j] + 1] = (dp[i + r[j] + 1] - dp[i]) % inf;
    }
  }
  if (dp[n] < 0)
    dp[n] += inf;
  cout << dp[n] << endl;
}