Problem p04013 (C++)

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

using namespace std;
using ll = long long;
#define int ll

void init();
void solve();

#define rep(i, a) for (int i = 0; i < (int)(a); i++)
#define reps(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rrep(i, a) for (int i = (int)a - 1; i >= 0; i--)
#define rreps(i, a, b) for (int i = (int)(a)-1; i >= (int)(b); i--)
#define MP(a, b) make_pair((a), (b))
#define PB(a) push_back((a))
#define all(v) (v).begin(), (v).end()
#define PRINT(f)                                                               \
  if ((f)) {                                                                   \
    cout << (TRUE__) << endl;                                                  \
  } else {                                                                     \
    cout << FALSE__ << endl;                                                   \
  }
#define TRUE__ "Yes"
#define FALSE__ "No"
#define PERM(v) next_permutation(all(v))
#define UNIQUE(v)                                                              \
  sort(all(v));                                                                \
  (v).erase(unique(all(v)), v.end())
#define CIN(type, x)                                                           \
  type x;                                                                      \
  cin >> x

#ifdef LOCAL
#define lcout(a) cout << a
#define lcoutln(a) cout << a << endl
#define lcerr(a) cerr << a
#define lcerrln(a) cerr << a << endl
#else
#define lcout(a)
#define lcoutln(a)
#define lcerr(a)
#define lcerrln(a)
#endif
#define MOD 1000000007
#define PI 3.141592653589793238462643383

signed main() {
  init();
  solve();
}

ll dp[50][5500];
int zero;
int N, A;
vector<ll> v;

void init() {
  cin >> N;
  cin >> A;
  v.resize(N);
  rep(i, N) {
    cin >> v[i];
    v[i] -= A;
  }
  zero = N * A + 50;
  dp[0][zero] = 1;
}

void solve() {
  rep(i, N) {
    rep(j, 5500) {
      dp[i + 1][j] = dp[i][j];
      if (j - v[i] >= 0) {
        dp[i + 1][j] += dp[i][j - v[i]];
      }
    }
  }
  cout << dp[N][zero] - 1 << endl;
}


Fixed submission:
#include <bits/stdc++.h>

using namespace std;
using ll = long long;
#define int ll

void init();
void solve();

#define rep(i, a) for (int i = 0; i < (int)(a); i++)
#define reps(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rrep(i, a) for (int i = (int)a - 1; i >= 0; i--)
#define rreps(i, a, b) for (int i = (int)(a)-1; i >= (int)(b); i--)
#define MP(a, b) make_pair((a), (b))
#define PB(a) push_back((a))
#define all(v) (v).begin(), (v).end()
#define PRINT(f)                                                               \
  if ((f)) {                                                                   \
    cout << (TRUE__) << endl;                                                  \
  } else {                                                                     \
    cout << FALSE__ << endl;                                                   \
  }
#define TRUE__ "Yes"
#define FALSE__ "No"
#define PERM(v) next_permutation(all(v))
#define UNIQUE(v)                                                              \
  sort(all(v));                                                                \
  (v).erase(unique(all(v)), v.end())
#define CIN(type, x)                                                           \
  type x;                                                                      \
  cin >> x

#ifdef LOCAL
#define lcout(a) cout << a
#define lcoutln(a) cout << a << endl
#define lcerr(a) cerr << a
#define lcerrln(a) cerr << a << endl
#else
#define lcout(a)
#define lcoutln(a)
#define lcerr(a)
#define lcerrln(a)
#endif
#define MOD 1000000007
#define PI 3.141592653589793238462643383

signed main() {
  init();
  solve();
}

ll dp[51][5500];
int zero;
int N, A;
vector<ll> v;

void init() {
  cin >> N;
  cin >> A;
  v.resize(N);
  rep(i, N) {
    cin >> v[i];
    v[i] -= A;
  }
  zero = N * A + 50;
  dp[0][zero] = 1;
}

void solve() {
  rep(i, N) {
    rep(j, 5500) {
      dp[i + 1][j] = dp[i][j];
      if (j - v[i] >= 0) {
        dp[i + 1][j] += dp[i][j - v[i]];
      }
    }
  }
  cout << dp[N][zero] - 1 << endl;
}