Problem p02319 (C++) — buggy submission, verdict: Runtime Error

/// MD NAZMUS SAKIB
/// CSE@RUET@BD
#include <bits/stdc++.h>
#include <typeinfo>

#define vc(T) vector<T>
#define vcc(T, U) vector < pair<T, U>
#define mpvc(T, U) map < T, vector<U>
#define vcs vector<char *>
#define pb(x) push_back(x)
#define mpr make_pair
#define ui unsigned int
#define ll long long
#define mdr 10000007
#define cize 100000005
#define i(x) obj.in(x)
#define ii(x, y) obj.in(x, y)
#define iline(x) obj.in_line(x)
#define o(x) obj.out(x)
#define ocas obj.cases()
#define ln obj.out()
#define fio                                                                    \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(0)
using namespace std;
using namespace std;

class FastIO {
private:
  ui caseno;

public:
  FastIO() { caseno = 0; }

  void in(int &x) { scanf("%d", &x); }
  void in(ll &x) { scanf("%lld", &x); }
  void in(char &x) { scanf(" %c", &x); }
  void in(char (&x)[cize]) { scanf(" %s", x); }
  void in_line(char (&x)[cize]) { scanf(" %[^\\n]s", x); }
  template <typename T> void in(vc(T) & x, int n) {
    T t;
    while (n--) {
      in(t);
      x.pb(t);
    }
  }
  template <typename T, typename U> void in(vcc(T, U) > &x, int n) {
    T a;
    U b;
    while (n--) {
      in(a);
      in(b);
      x.pb(mpr(a, b));
    }
  }
  template <class T, class U> void in(mpvc(T, U) > &x, int n) {
    T a;
    U b;
    bool vis[cize];
    memset(vis, true, cize);
    vc(int) temp;
    while (n--) {
      in(a);
      in(b);
      if (vis[b]) {
        temp.clear();
        temp.pb(a);
        x.insert(mpr(b, temp));
      } else {
        x[b].pb(a);
      }
    }
  }

  void out() { printf("\\n"); }
  void out(const int &x) { printf("%d", x); }
  void out(const ll &x) { printf("%lld", x); }
  void out(const char &x) { printf("%c", x); }
  void out(const char (&x)[cize]) { printf("%s", x); }

  void cases() { printf("Case %u: ", ++caseno); }

  ~FastIO() {}
};

ll RT(ll n) {
  ll r = sqrt(n * 1.0) - 2;
  for (r; r * r <= n; r++) {
  }
  return r - 1;
}

template <class T> T binS(vc(T) & ara, int sz, T value) {
  int ret = -1;
  int lf = 0, rr = sz - 1, md;
  md = (lf + rr) / 2;
  while (lf <= rr) {
    if (ara[md] > value) {
      while (ara[md] > value) {
        md--;
      }
      return md;
    } else {
      lf = md + 1;
    }
    md = (lf + rr) / 2;
  }
  if (ret == -1)
    return sz - 1;
}

int main() {
  FastIO obj;
  int n, w, mx, sum;
  i(n);
  i(w);
  int val[n], wei[n];
  vc(char) vis;
  int tval = 0;
  for (int i = 0; i < n; i++) {
    i(val[i]);
    i(wei[i]);
    tval += val[i];
    vis.pb('1');
  }
  pair<int, vc(char)> knp[tval + 1];
  knp[0].first = 0;
  knp[0].second = vis;
  for (int i = 1; i <= tval; i++) {
    knp[i].first = cize;
    knp[i].second = vis;
  }
  int i;
  for (i = 1; i <= tval; i++) {
    for (int j = 0; j < n; j++) {
      if (val[j] <= i) {
        pair<int, vc(char)> tmp;
        tmp = knp[i - val[j]];
        if (tmp.first != cize && tmp.second[j] == '1') {
          tmp.second[j] = '0';
          if (tmp.first + wei[j] < knp[i].first) {
            knp[i].first = tmp.first + wei[j];
            knp[i].second = tmp.second;
          }
        }
      }
    }
  }
  i--;
  while (knp[i].first > w) {
    i--;
  }

  o(i);

  ln;
  return 0;
}


Error: 0

Fixed submission:

#include <iostream>
using namespace std;
int main(void) {
  long int n, w, a, b;
  cin >> n >> w;
  long int lis[n][2];
  for (int i = 0; i < n; i++) {
    cin >> lis[i][0] >> lis[i][1];
  }
  long int dp[w + 10];
  for (long int i = 0; i < w + 1; i++) {
    dp[i] = 0;
  }
  for (int i = 0; i < n; i++) {
    a = lis[i][0];
    b = lis[i][1];
    for (long int k = w + 10 - 1; k >= 0; k--) {
      if (b + k <= w) {
        dp[b + k] = max(dp[b + k], dp[k] + a);
      }
    }
  }
  cout << dp[w] << endl;
  return 0;
}