Problem p03172 (C++)

Buggy submission (status: Runtime Error):
// Program.cpp
// Author : Aaryan Srivastava
#include <bits/stdc++.h>
#include <chrono>
#include <random>
#define pb push_back
#define popb pop_back
#define ull unsigned long long
#define beg begin
#define mp make_pair
#define pii pair<int, int>
#define piii pair<pii, int>
#define rep(i, n) for (int(i) = 0; i < (n); i++)
#define repA(i, x, y) for (int i = (x); i <= (y); i++)
#define repD(i, x, y) for (int i = (x); i >= (y); i--)
#define all(c) (c).begin(), (c).end()
#define ff first
#define ss second
#define fill(a, val) memset(a, val, sizeof(a))
#define Randomize                                                              \
  mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
using ll = long long;
#define int ll
const int N = 2 * 1e5 + 5;
const int mod = 1e9 + 7;
const int inf = 1e18;
const int SZ = 101;
const double eps = 1e-9;
using namespace std;
#ifdef AaryanS
#define mycout cout
#define mycerr cerr
#endif

#ifndef AaryanS
#define mycout                                                                 \
  if (false)                                                                   \
  cout
#define mycerr                                                                 \
  if (false)                                                                   \
  cerr
#define AaryanS 0
#endif

int dp[100][2 * 100 * 1000 + 5] = {};
void solve() {
  int n, k;
  scanf("%lld%lld", &n, &k);
  vector<int> a(n);
  for (auto &it : a)
    scanf("%lld", &it);
  dp[0][0] = 1;
  for (int i = 0; i < n; ++i) {
    for (int cur = 0; cur <= k; ++cur) {
      dp[i + 1][cur] += dp[i][cur];
      dp[i + 1][cur] %= mod;
      dp[i + 1][cur + a[i] + 1] -= dp[i][cur];
      dp[i + 1][cur + a[i] + 1] %= mod;
      if (dp[i + 1][cur + a[i] + 1] < 0)
        dp[i + 1][cur + a[i] + 1] += mod;
    }
    for (int cur = 1; cur <= k; ++cur)
      dp[i + 1][cur] += dp[i + 1][cur - 1], dp[i + 1][cur] %= mod;
  }
  cout << dp[n][k];
}

int32_t main(int32_t argc, char *argv[]) {
  double t1 = clock();
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int TC = 1, t = 0;
  // cin >> TC ;
  while (t++ < TC) {
    // cout << "Case " << t << ":\n" ;
    solve();
  }
  mycerr << "Time : " << 1000 * (clock() - t1) / CLOCKS_PER_SEC << " ms\n";
  return 0;
}


Fixed submission:
// Program.cpp
// Author : Aaryan Srivastava
#include <bits/stdc++.h>
#include <chrono>
#include <random>
#define pb push_back
#define popb pop_back
#define ull unsigned long long
#define beg begin
#define mp make_pair
#define pii pair<int, int>
#define piii pair<pii, int>
#define rep(i, n) for (int(i) = 0; i < (n); i++)
#define repA(i, x, y) for (int i = (x); i <= (y); i++)
#define repD(i, x, y) for (int i = (x); i >= (y); i--)
#define all(c) (c).begin(), (c).end()
#define ff first
#define ss second
#define fill(a, val) memset(a, val, sizeof(a))
#define Randomize                                                              \
  mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
using ll = long long;
#define int ll
const int N = 2 * 1e5 + 5;
const int mod = 1e9 + 7;
const int inf = 1e18;
const int SZ = 101;
const double eps = 1e-9;
using namespace std;
#ifdef AaryanS
#define mycout cout
#define mycerr cerr
#endif

#ifndef AaryanS
#define mycout                                                                 \
  if (false)                                                                   \
  cout
#define mycerr                                                                 \
  if (false)                                                                   \
  cerr
#define AaryanS 0
#endif

int dp[101][2 * 100 * 1000 + 5] = {};
void solve() {
  int n, k;
  scanf("%lld%lld", &n, &k);
  vector<int> a(n);
  for (auto &it : a)
    scanf("%lld", &it);
  dp[0][0] = 1;
  for (int i = 0; i < n; ++i) {
    for (int cur = 0; cur <= k; ++cur) {
      dp[i + 1][cur] += dp[i][cur];
      dp[i + 1][cur] %= mod;
      dp[i + 1][cur + a[i] + 1] -= dp[i][cur];
      dp[i + 1][cur + a[i] + 1] %= mod;
      if (dp[i + 1][cur + a[i] + 1] < 0)
        dp[i + 1][cur + a[i] + 1] += mod;
    }
    for (int cur = 1; cur <= k; ++cur)
      dp[i + 1][cur] += dp[i + 1][cur - 1], dp[i + 1][cur] %= mod;
  }
  cout << dp[n][k];
}

int32_t main(int32_t argc, char *argv[]) {
  double t1 = clock();
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int TC = 1, t = 0;
  // cin >> TC ;
  while (t++ < TC) {
    // cout << "Case " << t << ":\n" ;
    solve();
  }
  mycerr << "Time : " << 1000 * (clock() - t1) / CLOCKS_PER_SEC << " ms\n";
  return 0;
}