Problem p03163 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
// #include<ext/pb_ds/assoc_container.hpp>
// #include<ext/pb_ds/tree_policy.hpp>
#define IOS                                                                    \
  ios_base::sync_with_stdio(0);                                                \
  cin.tie(0);                                                                  \
  cout.tie(0);
#define MAX 2000005
#define MOD 1000000007
#define pb push_back
#define mp make_pair
#define pii pair<ll, ll>
#define vi vector<ll>
#define vp vector<pii>
#define all(v) v.begin(), v.end()
#define lb(v, x) lower_bound(all(v), x)
#define ub(v, x) upper_bound(all(v), x)
#define sz(x) (ll) x.size()
#define F first
#define S second
#define FOR(i, a, b) for (ll i = a; i < b; ++i)
#define ROF(i, a, b) for (ll i = a; i >= b; --i)
#define trace(x) cerr << #x << ": " << x << '\n';
typedef long long ll;
using namespace std;
// using namespace __gnu_pbds;
// #define ordered_set tree<int, null_type, less<int>, rb_tree_tag,
// tree_order_statistics_node_update>

ll mexp(ll a, ll b) {
  ll ans = 1;
  a %= MOD;
  while (b) {
    if (b & 1)
      ans = ans * a % MOD;
    b >>= 1;
    a = a * a % MOD;
  }
  return ans;
}

ll gcd(ll a, ll b) {
  if (a == 0) {
    return b;
  }
  return gcd(b % a, a);
}

const int N = 105;

ll dp[N][N];

int main() {
  IOS

      int n,
      W;
  cin >> n >> W;
  ll w[n + 1], v[n + 1];
  FOR(i, 1, n + 1) { cin >> w[i] >> v[i]; }
  FOR(i, 1, n + 1) {
    FOR(j, 1, W + 1) {
      if (w[i] <= j) {
        dp[i][j] = max(dp[i - 1][j - w[i]] + v[i], dp[i - 1][j]);
      } else {
        dp[i][j] = dp[i - 1][j];
      }
    }
  }
  cout << dp[n][W];
  cerr << 1.0 / CLOCKS_PER_SEC << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
// #include<ext/pb_ds/assoc_container.hpp>
// #include<ext/pb_ds/tree_policy.hpp>
#define IOS                                                                    \
  ios_base::sync_with_stdio(0);                                                \
  cin.tie(0);                                                                  \
  cout.tie(0);
#define MAX 2000005
#define MOD 1000000007
#define pb push_back
#define mp make_pair
#define pii pair<ll, ll>
#define vi vector<ll>
#define vp vector<pii>
#define all(v) v.begin(), v.end()
#define lb(v, x) lower_bound(all(v), x)
#define ub(v, x) upper_bound(all(v), x)
#define sz(x) (ll) x.size()
#define F first
#define S second
#define FOR(i, a, b) for (ll i = a; i < b; ++i)
#define ROF(i, a, b) for (ll i = a; i >= b; --i)
#define trace(x) cerr << #x << ": " << x << '\n';
typedef long long ll;
using namespace std;
// using namespace __gnu_pbds;
// #define ordered_set tree<int, null_type, less<int>, rb_tree_tag,
// tree_order_statistics_node_update>

ll mexp(ll a, ll b) {
  ll ans = 1;
  a %= MOD;
  while (b) {
    if (b & 1)
      ans = ans * a % MOD;
    b >>= 1;
    a = a * a % MOD;
  }
  return ans;
}

ll gcd(ll a, ll b) {
  if (a == 0) {
    return b;
  }
  return gcd(b % a, a);
}

const int N = 105;

ll dp[N][100005];

int main() {
  IOS

      int n,
      W;
  cin >> n >> W;
  ll w[n + 1], v[n + 1];
  FOR(i, 1, n + 1) { cin >> w[i] >> v[i]; }
  FOR(i, 1, n + 1) {
    FOR(j, 1, W + 1) {
      if (w[i] <= j) {
        dp[i][j] = max(dp[i - 1][j - w[i]] + v[i], dp[i - 1][j]);
      } else {
        dp[i][j] = dp[i - 1][j];
      }
    }
  }
  cout << dp[n][W];
  cerr << 1.0 / CLOCKS_PER_SEC << endl;
  return 0;
}