Problem p02320 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <queue>
#include <stack>
#include <string>
#include <vector>
using namespace std;

const int INF = INT_MAX / 3;

void slidingMinimum(vector<int> &inputList, vector<int> &outputList,
                    int slideSize) {
  deque<int> dq;
  for (int i = 0; i < inputList.size(); i++) {
    while (!dq.empty()) {
      if (inputList[dq.back()] >= inputList[i]) {
        dq.pop_back();
      } else {
        break;
      }
    }
    dq.push_back(i);

    outputList.push_back(inputList[dq.front()]);
    if (dq.front() == i - slideSize + 1) {
      dq.pop_front();
    }
  }
  return;
}

int knapsackProblemWithLimitations(int W, vector<int> &v, vector<int> &w,
                                   vector<int> &m) {
  int N = v.size();
  int DP[W + 1][N];

  for (int i = 0; i < W + 1; i++) {
    for (int j = 0; j < N; j++) {
      DP[i][j] = 0;
    }
  }

  for (int i = 1; i < m[0] + 1; i++) {
    DP[w[0] * i][0] = v[0] * i;
  }

  for (int j = 1; j < N; j++) {
    for (int t = 0; t < w[j]; t++) {
      vector<int> b, c;
      for (int k = 0; (w[j] * k + t) < W + 1; k++) {
        b.push_back(DP[w[j] * k + t][j - 1] - k * v[j]);
      }

      //??¢??°???????°????????±???????????????§???????±???????????????§??\???
      for (int i = 0; i < b.size(); i++) {
        b[i] = -b[i];
      }
      slidingMinimum(b, c, m[j] + 1);
      for (int i = 0; i < c.size(); i++) {
        c[i] = -c[i];
      }
      /*
                  cout << endl;
                  for (int p=0;p<b.size();p++){
                      cout << b[p] << " ";
                  }
                  cout << endl <<endl;

                  cout << endl;
                  for (int p=0;p<c.size();p++){
                      cout << c[p] << " ";
                  }
                  cout << endl <<endl;
      */
      for (int k = 0; k < c.size(); k++) {
        DP[w[j] * k + t][j] = c[k] + k * v[j];
      }
    }
  }
  /*
      cout << endl;
      for (int i=0;i<W+1;i++){
          for (int j=0;j<N;j++){
              cout << DP[i][j] << " ";
          }
          cout << endl;
      }
      cout << endl;
  */
  int S = 0;
  for (int i = 0; i < W + 1; i++) {
    S = max(S, DP[i][N - 1]);
  }
  return S;
}

int main() {
  int N, W;
  cin >> N >> W;
  vector<int> v(N);
  vector<int> w(N);
  vector<int> m(N);
  for (int i = 0; i < N; i++) {
    cin >> v[i] >> w[i] >> m[i];
  }

  cout << knapsackProblemWithLimitations(W, v, w, m) << endl;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <queue>
#include <stack>
#include <string>
#include <vector>
using namespace std;

const int INF = INT_MAX / 3;

void slidingMinimum(vector<int> &inputList, vector<int> &outputList,
                    int slideSize) {
  deque<int> dq;
  for (int i = 0; i < inputList.size(); i++) {
    while (!dq.empty()) {
      if (inputList[dq.back()] >= inputList[i]) {
        dq.pop_back();
      } else {
        break;
      }
    }
    dq.push_back(i);

    outputList.push_back(inputList[dq.front()]);
    if (dq.front() == i - slideSize + 1) {
      dq.pop_front();
    }
  }
  return;
}

int knapsackProblemWithLimitations(int W, vector<int> &v, vector<int> &w,
                                   vector<int> &m) {
  int N = v.size();
  int DP[W + 1][N];

  for (int i = 0; i < W + 1; i++) {
    for (int j = 0; j < N; j++) {
      DP[i][j] = 0;
    }
  }

  for (int i = 1; i < min(m[0], W / w[0]) + 1; i++) {
    DP[w[0] * i][0] = v[0] * i;
  }

  for (int j = 1; j < N; j++) {
    for (int t = 0; t < w[j]; t++) {
      vector<int> b, c;
      for (int k = 0; (w[j] * k + t) < W + 1; k++) {
        b.push_back(DP[w[j] * k + t][j - 1] - k * v[j]);
      }

      //??¢??°???????°????????±???????????????§???????±???????????????§??\???
      for (int i = 0; i < b.size(); i++) {
        b[i] = -b[i];
      }
      slidingMinimum(b, c, m[j] + 1);
      for (int i = 0; i < c.size(); i++) {
        c[i] = -c[i];
      }
      /*
                  cout << endl;
                  for (int p=0;p<b.size();p++){
                      cout << b[p] << " ";
                  }
                  cout << endl <<endl;

                  cout << endl;
                  for (int p=0;p<c.size();p++){
                      cout << c[p] << " ";
                  }
                  cout << endl <<endl;
      */
      for (int k = 0; k < c.size(); k++) {
        DP[w[j] * k + t][j] = c[k] + k * v[j];
      }
    }
  }
  /*
      cout << endl;
      for (int i=0;i<W+1;i++){
          for (int j=0;j<N;j++){
              cout << DP[i][j] << " ";
          }
          cout << endl;
      }
      cout << endl;
  */
  int S = 0;
  for (int i = 0; i < W + 1; i++) {
    S = max(S, DP[i][N - 1]);
  }
  return S;
}

int main() {
  int N, W;
  cin >> N >> W;
  vector<int> v(N);
  vector<int> w(N);
  vector<int> m(N);
  for (int i = 0; i < N; i++) {
    cin >> v[i] >> w[i] >> m[i];
  }

  cout << knapsackProblemWithLimitations(W, v, w, m) << endl;
  return 0;
}