Problem p02662 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define ll long long int
#define ld long double
#define f first
#define s second
#define pb push_back
#define eb emplace_back
#define mk make_pair
#define mt make_tuple
#define MOD 998244353
#define fo(i, a, b) for (i = a; i < b; i++)
#define foe(i, a, b) for (i = a; i <= b; i++)
#define all(x) x.begin(), x.end()
#define vi vector<int>
#define vl vector<long long int>
#define pii pair<int, int>
#define pll pair<long long int, long long int>
#define vpii vector<pair<int, int>>
#define vpll vector<pair<long long int, long long int>>
#define boost                                                                  \
  ios::sync_with_stdio(false);                                                 \
  cin.tie(0)
using namespace std;
const int inf = 1e9 + 5;
const ll inf64 = 1e18 + 5;

ll add(ll x, ll y) {
  ll res = x + y;
  return (res >= MOD ? res - MOD : res);
}
ll mul(ll x, ll y) {
  ll res = x * y;
  return (res >= MOD ? res % MOD : res);
}
ll sub(ll x, ll y) {
  ll res = x - y;
  return (res < 0 ? res + MOD : res);
}
ll lcm(ll x, ll y) {
  ll res = (x * y) / __gcd(x, y);
  return res;
}
ll power(ll x, ll y) {
  ll res = 1;
  x %= MOD;
  while (y) {
    if (y & 1)
      res = mul(res, x);
    y >>= 1;
    x = mul(x, x);
  }
  return res;
}

const int MAX = 1e3 + 5;
ll dp[MAX][MAX];
int main() {
  boost;
  int n, s, i, j;
  cin >> n >> s;
  int arr[n];
  fo(i, 0, n) cin >> arr[i];
  ll inv = power(2, MOD - 2);
  dp[0][0] = power(2, n);
  fo(i, 0, n) {
    foe(j, 0, s) {
      if (arr[i] > j)
        dp[i + 1][j] = dp[i][j];
      else
        dp[i + 1][j] = add(dp[i][j], mul(dp[i][j - arr[i]], inv));
    }
  }
  cout << dp[n][s];
}


Fixed submission:
#include <bits/stdc++.h>
#define ll long long int
#define ld long double
#define f first
#define s second
#define pb push_back
#define eb emplace_back
#define mk make_pair
#define mt make_tuple
#define MOD 998244353
#define fo(i, a, b) for (i = a; i < b; i++)
#define foe(i, a, b) for (i = a; i <= b; i++)
#define all(x) x.begin(), x.end()
#define vi vector<int>
#define vl vector<long long int>
#define pii pair<int, int>
#define pll pair<long long int, long long int>
#define vpii vector<pair<int, int>>
#define vpll vector<pair<long long int, long long int>>
#define boost                                                                  \
  ios::sync_with_stdio(false);                                                 \
  cin.tie(0)
using namespace std;
const int inf = 1e9 + 5;
const ll inf64 = 1e18 + 5;

ll add(ll x, ll y) {
  ll res = x + y;
  return (res >= MOD ? res - MOD : res);
}
ll mul(ll x, ll y) {
  ll res = x * y;
  return (res >= MOD ? res % MOD : res);
}
ll sub(ll x, ll y) {
  ll res = x - y;
  return (res < 0 ? res + MOD : res);
}
ll lcm(ll x, ll y) {
  ll res = (x * y) / __gcd(x, y);
  return res;
}
ll power(ll x, ll y) {
  ll res = 1;
  x %= MOD;
  while (y) {
    if (y & 1)
      res = mul(res, x);
    y >>= 1;
    x = mul(x, x);
  }
  return res;
}

const int MAX = 3e3 + 5;
ll dp[MAX][MAX];
int main() {
  boost;
  int n, s, i, j;
  cin >> n >> s;
  int arr[n];
  fo(i, 0, n) cin >> arr[i];
  ll inv = power(2, MOD - 2);
  dp[0][0] = power(2, n);
  fo(i, 0, n) {
    foe(j, 0, s) {
      if (arr[i] > j)
        dp[i + 1][j] = dp[i][j];
      else
        dp[i + 1][j] = add(dp[i][j], mul(dp[i][j - arr[i]], inv));
    }
  }
  cout << dp[n][s];
}