Problem p03172 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

struct Benri {
  Benri() {
    std::cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(12);
  }
} benri;

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;
using vll = vector<long long>;
using vvll = vector<vll>;
using pll = pair<ll, ll>;
using ull = unsigned long long;

template <typename T> using PQ = priority_queue<T>;
template <typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define mp make_pair
#define F first
#define S second

template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}

constexpr long long MOD = 1000000007;
// constexpr long long MOD = 998244353;
// constexpr int INF = 1001001001;
constexpr ll INF = 1001001001001001001ll;
constexpr double EPS = 1e-10;
using number = long long;

ll dp[100][100005];

int main() {
  int N, K;
  cin >> N >> K;
  vi a(N + 1, 0);
  rep(i, N) cin >> a[i + 1];

  dp[0][0] = 1;
  for (int i = 1; i <= N; i++) {
    rep(j, K + 1) {
      dp[i][j] = dp[i - 1][j];
      if (j - 1 >= 0)
        dp[i][j] += dp[i][j - 1];
      if (j - 1 - a[i] >= 0)
        dp[i][j] -= dp[i - 1][j - 1 - a[i]];
      dp[i][j] = (dp[i][j] + MOD) % MOD;
    }
  }

  /*rep(i, N + 1) {
      rep(j, K + 1) {
          cout << dp[i][j] << " ";
      }
      cout << endl;
  }*/

  cout << dp[N][K] << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;

struct Benri {
  Benri() {
    std::cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(12);
  }
} benri;

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;
using vll = vector<long long>;
using vvll = vector<vll>;
using pll = pair<ll, ll>;
using ull = unsigned long long;

template <typename T> using PQ = priority_queue<T>;
template <typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define mp make_pair
#define F first
#define S second

template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}

constexpr long long MOD = 1000000007;
// constexpr long long MOD = 998244353;
// constexpr int INF = 1001001001;
constexpr ll INF = 1001001001001001001ll;
constexpr double EPS = 1e-10;
using number = long long;

ll dp[105][100005];

int main() {
  int N, K;
  cin >> N >> K;
  vi a(N + 1, 0);
  rep(i, N) cin >> a[i + 1];

  dp[0][0] = 1;
  for (int i = 1; i <= N; i++) {
    rep(j, K + 1) {
      dp[i][j] = dp[i - 1][j];
      if (j - 1 >= 0)
        dp[i][j] += dp[i][j - 1];
      if (j - 1 - a[i] >= 0)
        dp[i][j] -= dp[i - 1][j - 1 - a[i]];
      dp[i][j] = (dp[i][j] + MOD) % MOD;
    }
  }

  /*rep(i, N + 1) {
      rep(j, K + 1) {
          cout << dp[i][j] << " ";
      }
      cout << endl;
  }*/

  cout << dp[N][K] << endl;
}