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

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <set>
#include <string>
#include <vector>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define INT(a) int((a) + 1e-9)
#define HOU 1000000007
#define INF 3e9
#define SUPpl 202
#define SUPmaxw 10002

// rsss[pi][qi][w] = [0:pi] dake tukatte, saigoni tukawanakattanoga qi-1 de, w
// tukuru kumiawase
int orss[SUPpl][SUPmaxw]; // orss=rsss[pi-1]
int nrss[SUPpl][SUPmaxw]; // nrss=rsss[pi]

int main() {
  int pl, maxw;
  cin >> pl >> maxw;
  int ws[pl];
  FOR(pi, 0, pl) { cin >> ws[pi]; }
  sort(ws, ws + pl, greater<int>());

  FOR(qi, 0, pl + 1) {
    FOR(w, 0, maxw + 1) {
      nrss[qi][w] = 0;
      nrss[qi][w] = 0;
    }
  }
  nrss[0][0] = 1;

  /*
  cout<<"pi:"<<0<<", qi:"<<0<<", w:"<<0<<", rsss[pi][qi][w]:"<<1<<endl;
  */

  FOR(pi, 1, pl + 1) {
    FOR(qi, 0, pl + 1) {
      FOR(w, 0, maxw + 1) {
        orss[qi][w] = nrss[qi][w];
        nrss[qi][w] = 0;
      }
    }

    // when pi>qi: rsss[pi][qi][w] = rsss[pi-1][qi][w-ws[pi-1]]
    FOR(qi, 0, pi) {
      FOR(w, 0, maxw + 1) {
        if (w - ws[pi - 1] >= 0) {
          nrss[qi][w] = orss[qi][w - ws[pi - 1]] % HOU;
        }
      }
    }

    // when pi==qi: rsss[pi][qi][w] = rsss[pi-1][0][w]+..+rsss[pi-1][qi-1][w]
    FOR(oqi, 0, pi) {
      FOR(w, 0, maxw + 1) { nrss[pi][w] = (nrss[pi][w] + orss[oqi][w]) % HOU; }
    }

    // when pi<qi: rsss[pi][qi][w]=0

    /*
    FOR(qi,0,pl+1){
            FOR(w,0,maxw+1){
                    if(nrss[qi][w]!=0){
                            cout<<"pi:"<<pi<<", qi:"<<qi<<", w:"<<w<<",
    rsss[pi][qi][w]:"<<nrss[qi][w]<<endl;
                    }
            }
    }
    */
  }

  int re = nrss[0][maxw];
  FOR(qi, 1, pl + 1) {
    FOR(w, 0, maxw + 1) {
      if (w + ws[qi - 1] > maxw) {
        re = (re + nrss[qi][w]) % HOU;
      }
    }
  }

  cout << re << endl;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <set>
#include <string>
#include <vector>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define INT(a) int((a) + 1e-9)
#define HOU 1000000007
#define INF 3e9

int main() {
  int pl, maxw;
  cin >> pl >> maxw;
  int ws[pl];
  FOR(pi, 0, pl) { cin >> ws[pi]; }
  sort(ws, ws + pl, greater<int>());
  // rsss[pi][qi][w] = [0:pi] dake tukatte, saigoni tukawanakattanoga qi-1 de, w
  // tukuru kumiawase
  int orss[pl + 1][maxw + 1]; // orss=rsss[pi-1]
  int nrss[pl + 1][maxw + 1]; // nrss=rsss[pi]

  FOR(qi, 0, pl + 1) {
    FOR(w, 0, maxw + 1) {
      nrss[qi][w] = 0;
      nrss[qi][w] = 0;
    }
  }
  nrss[0][0] = 1;

  /*
  cout<<"pi:"<<0<<", qi:"<<0<<", w:"<<0<<", rsss[pi][qi][w]:"<<1<<endl;
  */

  FOR(pi, 1, pl + 1) {
    FOR(qi, 0, pl + 1) {
      FOR(w, 0, maxw + 1) {
        orss[qi][w] = nrss[qi][w];
        nrss[qi][w] = 0;
      }
    }

    // when pi>qi: rsss[pi][qi][w] = rsss[pi-1][qi][w-ws[pi-1]]
    FOR(qi, 0, pi) {
      FOR(w, 0, maxw + 1) {
        if (w - ws[pi - 1] >= 0) {
          nrss[qi][w] = orss[qi][w - ws[pi - 1]] % HOU;
        }
      }
    }

    // when pi==qi: rsss[pi][qi][w] = rsss[pi-1][0][w]+..+rsss[pi-1][qi-1][w]
    FOR(oqi, 0, pi) {
      FOR(w, 0, maxw + 1) { nrss[pi][w] = (nrss[pi][w] + orss[oqi][w]) % HOU; }
    }

    // when pi<qi: rsss[pi][qi][w]=0

    /*
    FOR(qi,0,pl+1){
            FOR(w,0,maxw+1){
                    if(nrss[qi][w]!=0){
                            cout<<"pi:"<<pi<<", qi:"<<qi<<", w:"<<w<<",
    rsss[pi][qi][w]:"<<nrss[qi][w]<<endl;
                    }
            }
    }
    */
  }

  int re = nrss[0][maxw];
  FOR(qi, 1, pl + 1) {
    FOR(w, 0, maxw + 1) {
      if (w + ws[qi - 1] > maxw) {
        re = (re + nrss[qi][w]) % HOU;
      }
    }
  }

  cout << re << endl;
}