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

#include <algorithm>
#include <bitset>
#include <cctype>
#include <complex>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <limits.h>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <string>
#include <vector>

#define VARIABLE(x) cerr << #x << "=" << x << endl
#define BINARY(x) static_cast<bitset<16>>(x);
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, m, n) for (int i = m; i < (int)(n); i++)
#define if_range(x, y, w, h)                                                   \\
  if (0 <= (int)(x) && (int)(x) < (int)(w) && 0 <= (int)(y) &&                 \\
      (int)(y) < (int)(h))

const int INF = 1000000000;
const double EPS = 1e-8;
const double PI = 3.14159;
int dx[4] = {-1, 0, 1, 0}, dy[4] = {0, -1, 0, 1};
using namespace std;
// typedef pair<int, int> P;

/** Problem0573 : Night Market **/
vector<int> A, B;
int N, T, S;
int dp[3001][3001];

int solve(int time, int market) {
  if (time > T || market > N)
    return 0;

  if (dp[time][market] >= 0)
    return dp[time][market];

  // 遊ばない
  int res = solve(time, market + 1);

  // 遊ぶ
  if (time <= S) {
    if (time + B[market] <= S)
      res = max(res, A[market] + solve(time + B[market], market + 1));
    else if (S + B[market] <= T)
      res = max(res, A[market] + solve(S + B[market], market + 1));
  } else {
    if (time + B[market] <= T)
      res = max(res, A[market] + solve(time + B[market], market + 1));
  }

  return dp[time][market] = res;
}

int main() {
  cin >> N >> T >> S;
  A.resize(N);
  B.resize(N);
  memset(dp, -1, sizeof(dp));
  rep(i, N) { cin >> A[i] >> B[i]; }
  cout << solve(0, 0) << endl;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <bitset>
#include <cctype>
#include <complex>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <limits.h>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <string>
#include <vector>

#define VARIABLE(x) cerr << #x << "=" << x << endl
#define BINARY(x) static_cast<bitset<16>>(x);
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, m, n) for (int i = m; i < (int)(n); i++)
#define if_range(x, y, w, h)                                                   \\
  if (0 <= (int)(x) && (int)(x) < (int)(w) && 0 <= (int)(y) &&                 \\
      (int)(y) < (int)(h))

const int INF = 1000000000;
const double EPS = 1e-8;
const double PI = 3.14159;
int dx[4] = {-1, 0, 1, 0}, dy[4] = {0, -1, 0, 1};
using namespace std;
// typedef pair<int, int> P;

/** Problem0573 : Night Market **/
vector<int> A, B;
int N, T, S;
int dp[3000][3000];

int solve(int time, int market) {
  if (time > T || market > N)
    return 0;

  if (dp[time][market] >= 0)
    return dp[time][market];

  // 遊ばない
  int res = solve(time, market + 1);

  // 遊ぶ
  if (time <= S) {
    if (time + B[market] <= S)
      res = max(res, A[market] + solve(time + B[market], market + 1));
    else if (S + B[market] <= T)
      res = max(res, A[market] + solve(S + B[market], market + 1));
  } else {
    if (time + B[market] <= T)
      res = max(res, A[market] + solve(time + B[market], market + 1));
  }

  return dp[time][market] = res;
}

int main() {
  cin >> N >> T >> S;
  A.resize(N);
  B.resize(N);
  memset(dp, -1, sizeof(dp));
  rep(i, N) { cin >> A[i] >> B[i]; }
  cout << solve(0, 0) << endl;
}