Problem p03163 (C++)

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

using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
using vvl = vector<vl>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;
using vb = vector<bool>;
using vs = vector<string>;
const ll oo = 0x3f3f3f3f3f3f3f3fLL;
const ld eps = 1e-9;
#define sz(c) ll((c).size())
#define all(c) begin(c), end(c)
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define xx first
#define yy second
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define FORD(i, a, b) for (ll i = ll(b) - 1; i >= (a); i--)
#define TR(X)                                                                  \
  ({                                                                           \
    if (1)                                                                     \
      cerr << "TR: " << (#X) << " = " << (X) << endl;                          \
  })

ll weight[101] = {0};
ll value[101] = {0};
ll maximum[100][100000] = {};
ll n, w;

ll knapsack(ll item, ll weightLeft) {
  if (weightLeft == 0) {
    return 0;
  }
  if (weightLeft < 0) {
    return -oo;
  }
  if (item > n) {
    return 0;
  }
  if (maximum[item][weightLeft] != -1) {
    return maximum[item][weightLeft];
  }
  ll res;

  res = max(knapsack(item + 1, weightLeft - weight[item]) + value[item],
            knapsack(item + 1, weightLeft));

  maximum[item][weightLeft] = res;
  return res;
}

int main() {
  cin.sync_with_stdio(0);

  fill(&maximum[0][0], &maximum[0][0] + sizeof(maximum) / sizeof(maximum[0][0]),
       -1);

  cin >> n >> w;

  FOR(i, 1, n + 1) {
    ll tw, tv;
    cin >> weight[i] >> value[i];
  }

  cout << knapsack(1, w);
}

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

using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
using vvl = vector<vl>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;
using vb = vector<bool>;
using vs = vector<string>;
const ll oo = 0x3f3f3f3f3f3f3f3fLL;
const ld eps = 1e-9;
#define sz(c) ll((c).size())
#define all(c) begin(c), end(c)
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define xx first
#define yy second
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define FORD(i, a, b) for (ll i = ll(b) - 1; i >= (a); i--)
#define TR(X)                                                                  \
  ({                                                                           \
    if (1)                                                                     \
      cerr << "TR: " << (#X) << " = " << (X) << endl;                          \
  })

ll weight[101] = {0};
ll value[101] = {0};
ll maximum[105][100005] = {};
ll n, w;

ll knapsack(ll item, ll weightLeft) {
  if (weightLeft == 0) {
    return 0;
  }
  if (weightLeft < 0) {
    return -oo;
  }
  if (item > n) {
    return 0;
  }
  if (maximum[item][weightLeft] != -1) {
    return maximum[item][weightLeft];
  }
  ll res;

  res = max(knapsack(item + 1, weightLeft - weight[item]) + value[item],
            knapsack(item + 1, weightLeft));

  maximum[item][weightLeft] = res;
  return res;
}

int main() {
  cin.sync_with_stdio(0);

  fill(&maximum[0][0], &maximum[0][0] + sizeof(maximum) / sizeof(maximum[0][0]),
       -1);

  cin >> n >> w;

  FOR(i, 1, n + 1) {
    ll tw, tv;
    cin >> weight[i] >> value[i];
  }

  cout << knapsack(1, w);
}