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

#include <bits/stdc++.h>
/*
CE
#include<algorithm>
#include<bitset>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<deque>
#include<iostream>
#include<list>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<vector>

*/
using namespace std;
#define rep(i, a, n) for (int i = a; i <= n; i++)
#define per(i, a, n) for (int i = n; i >= a; i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
#define mem(a, b) memset(a, b, sizeof(a))
#define ios                                                                    \\
  std::ios::sync_with_stdio(false);                                            \\
  std::cin.tie(0);                                                             \\
  std::cout.tie(0);
// ios  can not be used with scanf,printf.  IF  ios MUST cin,cout.
typedef long long ll;
typedef vector<int> VI;
typedef pair<int, int> PII;
const ll mod = 998244353;
const int INF = 0x3f3f3f3f;
ll ksm(ll a, ll b) {
  ll res = 1;
  a %= mod;
  for (; b; b >>= 1) {
    if (b & 1)
      res = res * a % mod;
    a = a * a % mod;
  }
  return res;
}
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }

const int N = 2e5 + 10;
int n, k;
ll sum[N], dp[N];
int L[N], R[N];
ll get(int l, int r) {
  if (l <= 1)
    l = 1;
  return ((sum[r] - sum[l - 1]) % mod + mod) % mod;
}
int main() {
  scanf("%d%d", &n, &k);
  rep(i, 1, k) { scanf("%d%d", &L[i], &R[i]); }
  dp[1] = sum[1] = 1;
  rep(i, 1, n) {
    rep(j, 1, k) { dp[i] = (dp[i] + get(i - R[j], i - L[j])) % mod; }
    sum[i] = sum[i - 1] + dp[i];
  }
  printf("%lld\\n", dp[n]);
  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
/*
CE
#include<algorithm>
#include<bitset>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<deque>
#include<iostream>
#include<list>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<vector>

*/
using namespace std;
#define rep(i, a, n) for (int i = a; i <= n; i++)
#define per(i, a, n) for (int i = n; i >= a; i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
#define mem(a, b) memset(a, b, sizeof(a))
#define ios                                                                    \\
  std::ios::sync_with_stdio(false);                                            \\
  std::cin.tie(0);                                                             \\
  std::cout.tie(0);
// ios  can not be used with scanf,printf.  IF  ios MUST cin,cout.
typedef long long ll;
typedef vector<int> VI;
typedef pair<int, int> PII;
const ll mod = 998244353;
const int INF = 0x3f3f3f3f;
ll ksm(ll a, ll b) {
  ll res = 1;
  a %= mod;
  for (; b; b >>= 1) {
    if (b & 1)
      res = res * a % mod;
    a = a * a % mod;
  }
  return res;
}
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }

const int N = 1e5 + 10;
int n, k;
ll sum[N], dp[N];
int L[N], R[N];
ll get(int l, int r) {
  if (l <= 1)
    l = 1;
  return ((sum[r] - sum[l - 1]) % mod + mod) % mod;
}
int main() {
  scanf("%d%d", &n, &k);
  rep(i, 1, k) { scanf("%d%d", &L[i], &R[i]); }
  dp[1] = sum[1] = 1;
  rep(i, 1, n) {
    rep(j, 1, k) { dp[i] = (dp[i] + get(i - R[j], i - L[j])) % mod; }
    sum[i] = sum[i - 1] + dp[i];
  }
  printf("%lld\\n", dp[n]);
  return 0;
}