alexjercan/bugnet huggingface dataset:
Problem p00496 (C++) — buggy submission, verdict: Memory Limit Exceeded

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

using namespace std;

int dp[3001][3002];

int A[3001];
int B[3001];

int main() {

  int N, T, S;

  scanf("%d %d %d", &N, &T, &S);

  for (int i = 0; i < N; i++)
    scanf("%d %d", &A[i], &B[i]);

  int M = 0;

  for (int i = 0; i < N; i++) {
    for (int j = 0; j <= S; j++) {
      if (j < B[i])
        dp[i + 1][j] = dp[i][j];
      else
        dp[i + 1][j] = max(dp[i][j], dp[i][j - B[i]] + A[i]);
    }
  }

  for (int i = N - 1; i >= 0; i--) {
    for (int j = S + 1; j <= T + 1; j++) {
      if (j - 1 - S < B[i])
        dp[i][j] = dp[i + 1][j];
      else
        dp[i][j] = max(dp[i + 1][j], dp[i + 1][j - B[i]] + A[i]);
    }
  }

  for (int i = 0; i <= N; i++) {
    if (M < dp[i][S] + dp[i][T + 1])
      M = dp[i][S] + dp[i][T + 1];
  }

  printf("%d\\n", M);

  return 0;
}

Error: MLE

Fixed submission:

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

using namespace std;

int dp[3001][3001];
int dq[3001][3001];
int A[3001];
int B[3001];

int main() {

  int N, T, S;

  scanf("%d %d %d", &N, &T, &S);

  for (int i = 0; i < N; i++)
    scanf("%d %d", &A[i], &B[i]);

  int M = 0;

  for (int i = 0; i < N; i++) {
    for (int j = 0; j <= S; j++) {
      if (j < B[i])
        dp[i + 1][j] = dp[i][j];
      else
        dp[i + 1][j] = max(dp[i][j], dp[i][j - B[i]] + A[i]);
    }
  }

  for (int i = N - 1; i >= 0; i--) {
    for (int j = 0; j <= T - S; j++) {
      if (j < B[i])
        dq[i][j] = dq[i + 1][j];
      else
        dq[i][j] = max(dq[i + 1][j], dq[i + 1][j - B[i]] + A[i]);
    }
  }

  for (int i = 0; i <= N; i++) {
    if (M < dp[i][S] + dq[i][T - S])
      M = dp[i][S] + dq[i][T - S];
  }

  printf("%d\\n", M);

  return 0;
}
Problem p00496 (C++) — buggy submission, verdict: Time Limit Exceeded

#include "algorithm"
#include "climits"
#include "functional"
#include "iomanip"
#include "iostream"
#include "list"
#include "map"
#include "math.h"
#include "queue"
#include "random"
#include "set"
#include "stack"
#include "string"
#include "unordered_map"
#include "utility"

using namespace std;
const long long int MOD = 1000000007;

int N, T, S;
int cost[3001];
int fun[3001];
int dp[3001];
int ans;

int main() {
  ios::sync_with_stdio(false);
  cin >> N >> T >> S;
  for (int i = 1; i <= N; i++)
    cin >> fun[i] >> cost[i];
  for (int i = 1; i <= N; i++) {
    for (int j = T; j >= cost[i]; j--) {
      if (j - cost[i] >= S || j <= S)
        dp[j] = max(dp[j], dp[j - cost[i]] + fun[i]);
    }
  }
  for (int i = 1; i <= T; i++)
    ans = max(ans, dp[i]);
  cout << ans << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include "algorithm"
#include "climits"
#include "functional"
#include "iomanip"
#include "iostream"
#include "list"
#include "map"
#include "math.h"
#include "queue"
#include "random"
#include "set"
#include "stack"
#include "string"
#include "unordered_map"
#include "utility"

using namespace std;
const long long int MOD = 1000000007;

int N, T, S;
int cost[3001];
int fun[3001];
int dp[3001][3001];
int ans;

int main() {
  ios::sync_with_stdio(false);
  cin >> N >> T >> S;
  for (int i = 1; i <= N; i++)
    cin >> fun[i] >> cost[i];
  for (int i = 0; i < S; i++) {
    for (int j = 0; j <= N; j++) {
      if (i)
        dp[i][j] = max(dp[i - 1][j], dp[i][j]);
      for (int k = j + 1; k <= N; k++) {
        if (i + cost[k] <= S) {
          //	cout << dp[i + cost[k]][k] << " " << dp[i][j] << endl;
          dp[i + cost[k]][k] = max(dp[i + cost[k]][k], dp[i][j] + fun[k]);
          // cout << i + cost[k] << " " << k << " " << dp[i + cost[k]][k] <<
          // endl;
        }
      }
    }
  }
  for (int i = S; i <= T; i++) {
    for (int j = 0; j <= N; j++) {
      if (i)
        dp[i][j] = max(dp[i][j], dp[i - 1][j]);
      for (int k = j + 1; k <= N; k++) {
        if (i + cost[k] <= T) {
          dp[i + cost[k]][k] = max(dp[i + cost[k]][k], dp[i][j] + fun[k]);
          // cout << i + cost[k] << " " << k << " " << dp[i + cost[k]][k] <<
          // endl;
        }
      }
    }
  }
  for (int i = 0; i <= N; i++) {
    // cout << dp[T][i] << endl;
    ans = max(ans, dp[T][i]);
  }
  cout << ans << endl;
  return 0;
}
Problem p00496 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
const int dx[] = {0, 1, 0, -1, 1, -1, -1, 1};
const int dy[] = {-1, 0, 1, 0, 1, 1, -1, -1};
const int INF = 1 << 30;
const double EPS = 1e-15;
#define PB push_back
#define mk make_pair
#define fi first
#define se second
#define ll long long
#define reps(i, j, k) for (int i = (j); i < (k); i++)
#define rep(i, j) reps(i, 0, j)
#define MOD 1000000007
typedef pair<int, int> Pii;
typedef pair<Pii, Pii> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
vector<Pii> data;
int N, T, S;
int memo[3001][3001];
int solve(int index, int t) {
  if (index == N || t >= T)
    return 0;
  if (memo[index][t] != -1)
    return memo[index][t];

  int ret = max(solve(index, t + 1), solve(index + 1, t));
  bool f = true;

  if (t < S && t + data[index].se > S)
    f = false;
  if (t + data[index].se > T)
    f = false;

  if (f)
    ret = max(ret, solve(index + 1, t + data[index].se) + data[index].fi);
  // printf("{%d,%d} = %d\\n",index,t,ret);
  return memo[index][t] = ret;
}
int main() {
  memset(memo, -1, sizeof(memo));
  scanf("%d%d%d", &N, &T, &S);
  rep(i, N) {
    int a, b;
    scanf("%d%d", &a, &b);
    data.PB(Pii(a, b));
  }
  printf("%d\\n", solve(0, 0));
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
const int dx[] = {0, 1, 0, -1, 1, -1, -1, 1};
const int dy[] = {-1, 0, 1, 0, 1, 1, -1, -1};
const int INF = 1 << 30;
const double EPS = 1e-15;
#define PB push_back
#define mk make_pair
#define fi first
#define se second
#define ll long long
#define reps(i, j, k) for (int i = (j); i < (k); i++)
#define rep(i, j) reps(i, 0, j)
#define MOD 1000000007
typedef pair<int, int> Pii;
typedef pair<Pii, Pii> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
vector<Pii> data;
int N, T, S;
int memo[3001][3001];
int solve(int index, int t) {
  if (index == N || t > T)
    return 0;
  if (memo[index][t])
    return memo[index][t];

  int ret = max(solve(index, t + 1), solve(index + 1, t));
  bool f = true;

  if (t < S && t + data[index].se > S)
    f = false;
  if (t + data[index].se > T)
    f = false;

  if (f)
    ret = max(ret, solve(index + 1, t + data[index].se) + data[index].fi);
  // printf("{%d,%d} = %d\\n",index,t,ret);
  return memo[index][t] = ret;
}
int main() {
  scanf("%d%d%d", &N, &T, &S);
  rep(i, N) {
    int a, b;
    scanf("%d%d", &a, &b);
    data.PB(Pii(a, b));
  }
  printf("%d\\n", solve(0, 0));
  return 0;
}
Problem p00496 (C++) — buggy submission, verdict: Memory Limit Exceeded

#include <algorithm>
#include <cstdio>
using namespace std;
int dp[3001][3001] = {};
int x[3001][2];
int n, t, s, ans = 0;
int main() {
  scanf("%d %d %d", &n, &t, &s);
  for (int i = 1; i <= n; i++) {
    scanf("%d %d", &x[i][0], &x[i][1]);
  }
  for (int i = x[1][1]; i <= t; i++) {
    dp[1][i] = x[1][0];
  }
  for (int i = 1; i < n; i++) {
    for (int j = 0; j <= t; j++) {
      if (j - x[i + 1][1] < 0) {
        if (j == 0) {
          dp[i + 1][j] = dp[i][j];
        } else {
          dp[i + 1][j] = max(dp[i + 1][j - 1], dp[i][j]);
        }
      } else {
        if (j > s && j - x[i + 1][1] < s) {
          dp[i + 1][j] = max(dp[i + 1][j - 1], dp[i][j]);
        } else {
          dp[i + 1][j] = max(dp[i][j], dp[i][j - x[i + 1][1]] + x[i + 1][0]);
          if (j != 0) {
            dp[i + 1][j] = max(dp[i + 1][j], dp[i + 1][j - 1]);
          }
        } /*DEGwer*/
      }
      ans = max(ans, dp[i + 1][j]);
    }
  }
  printf("%d\\n", ans);
  return 0;
}

Error: MLE

Fixed submission:

#include <algorithm>
#include <cstdio>
using namespace std;
long long dp[3001][3001] = {};
long long x[3001][2];
long long n, t, s;
int main() {
  scanf("%lld %lld %lld", &n, &t, &s);
  for (int i = 1; i <= n; i++) {
    scanf("%lld %lld", &x[i][0], &x[i][1]);
  }
  dp[1][x[1][1]] = x[1][0];
  for (int i = 1; i < n; i++) {
    for (long long j = 0; j <= t; j++) {
      if (j - x[i + 1][1] < 0) {
        dp[i + 1][j] = dp[i][j];
      } else {
        if (j > s && j - x[i + 1][1] < s) {
          dp[i + 1][j] = dp[i][j];
        } else {
          long long maxi = 0;
          for (int k = 0; k <= j - x[i + 1][1]; k++) {
            maxi = max(maxi, dp[i][k]);
          }
          dp[i + 1][j] = max(dp[i][j], maxi + x[i + 1][0]);
        }
      }
    } /*DEGwer*/
  }

  // for(int i=1;i<=n;i++){
  //	for(int j=0;j<=t;j++){
  //		printf("%d ",dp[i][j]);
  //	}
  //	printf("\\n");
  // }
  long long ans = 0;
  for (int i = 0; i <= t; i++) {
    ans = max(ans, dp[n][i]);
  }
  printf("%lld\\n", ans);
  scanf("%d", &n);
  return 0;
}
Problem p00496 (C++) — buggy submission, verdict: Memory Limit Exceeded


#include <algorithm>
#include <iostream>
using namespace std;

int mem[5000][5000], A[5000], B[5000], N, T, S;
int main() {
  int ans = 0;
  cin >> N >> T >> S;
  for (int i = 1; i <= N; i++)
    cin >> A[i] >> B[i];

  for (int n = 1; n <= N; n++) {
    for (int t = 1; t <= T; t++) {
      mem[n][t] = max(mem[n - 1][t], mem[n][t - 1]);
      if (!(t - B[n] < S && t > S) && t >= B[n])
        mem[n][t] = max(mem[n - 1][t - B[n]] + A[n], mem[n][t]);
    }
  }
  cout << mem[N][T] << endl;
}

Error: MLE

Fixed submission:


#include <algorithm>
#include <iostream>
using namespace std;

int mem[10000][10000], A[10000], B[10000], N, T, S;
int main() {
  int ans = 0;
  cin >> N >> T >> S;
  for (int i = 1; i <= N; i++)
    cin >> A[i] >> B[i];

  for (int n = 1; n <= N; n++) {
    for (int t = 1; t <= T; t++) {
      mem[n][t] = max(mem[n - 1][t], mem[n][t - 1]);
      if (!(t - B[n] < S && t > S) && t >= B[n])
        mem[n][t] = max(mem[n - 1][t - B[n]] + A[n], mem[n][t]);
    }
  }
  cout << mem[N][T] << endl;
}
Problem p00496 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;

int main() {
  int n, t, s, a[3000], b[3000];
  static int dp[3002][3001] = {};
  cin >> n >> t >> s;
  for (int i = 0; i < n; i++)
    cin >> a[i] >> b[i];
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= s; j++) {
      if (j - b[i - 1] >= 0)
        dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - b[i - 1]] + a[i - 1]);
      else
        dp[i][j] = dp[i - 1][j];
    }
  }
  for (int i = n; i >= 1; i--) {
    for (int j = s + 1; j <= t; j++) {
      if (j - b[i - 1] >= s + 1)
        dp[i][j] = max(dp[i + 1][j], dp[i + 1][j - b[i - 1]] + a[i - 1]);
      else if (j - b[i - 1] == s)
        dp[i][j] = max(dp[i + 1][j], a[i - 1]);
      else
        dp[i][j] = dp[i + 1][j];
    }
  }
  int ma = 0;
  for (int i = 0; i <= n; i++) {
    ma = max(ma, dp[i][s] + dp[i + 1][t]);
    // for(int j = 0;j <= t;j++) cout << dp[i][j] << " ";
    // cout << endl;
  }
  cout << ma << endl;
  return 0;
}

Error: -11

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  int n, t, s, a[3000], b[3000];
  int dp[3002][3001] = {};
  cin >> n >> t >> s;
  for (int i = 0; i < n; i++)
    cin >> a[i] >> b[i];
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= s; j++) {
      if (j - b[i - 1] >= 0)
        dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - b[i - 1]] + a[i - 1]);
      else
        dp[i][j] = dp[i - 1][j];
    }
  }
  for (int i = n; i >= 1; i--) {
    for (int j = s + 1; j <= t; j++) {
      if (j - b[i - 1] >= s + 1)
        dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - b[i - 1]] + a[i - 1]);
      else if (j - b[i - 1] == s)
        dp[i][j] = max(dp[i - 1][j], a[i - 1]);
      else
        dp[i][j] = dp[i - 1][j];
    }
  }
  int ma = 0;
  for (int i = 0; i <= n; i++) {
    ma = max(ma, dp[i][s] + dp[i + 1][t]);
    /*for(int j = 0;j <= t;j++) cout << dp[i][j] << " ";
    cout << endl;*/
  }
  cout << ma << endl;
  return 0;
}
Problem p00496 (C++) — buggy submission, verdict: Memory Limit Exceeded

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define reep(n1, n2, n3) for (int n1 = n3; n1 < n2; n1++)
#define rep(n1, n2) reep(n1, n2, 0)
#define pb push_back
#define mp make_pair
#define fr first
#define sc second
#define INF 1e9
using namespace std;
typedef long long int lint;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<pair<int, int>> vp;
typedef pair<int, int> pi2;
typedef pair<int, pair<int, int>> pi3;
typedef vector<string> vs;
typedef pair<double, double> pdd;
const double PI = acos(-1.0);
int dp1[3001][3001];
int fn[3010];
int co[3010];
int main() {
  int n, t, s;
  cin >> n >> t >> s;
  rep(i, n) {
    cin >> fn[i];
    cin >> co[i];
  }
  reep(i, n + 1, 1) {
    reep(j, s + 1, 1) {
      dp1[i][j] = max(dp1[i][j - 1], dp1[i - 1][j]);
      if (co[i - 1] <= j)
        dp1[i][j] = max(dp1[i][j], dp1[i - 1][j - co[i - 1]] + fn[i - 1]);
    }
  }
  rep(i, n + 1) dp1[i][0] = dp1[i][s];
  rep(i, n + 1) reep(j, t + 1, 1) dp1[i][j] = 0;
  reep(i, n + 1, 1) {
    reep(j, t - s + 1, 1) {
      dp1[i][j] = max(dp1[i][j - 1], dp1[i - 1][j]);
      if (co[i - 1] <= j)
        dp1[i][j] = max(dp1[i][j], dp1[i - 1][j - co[i - 1]] + fn[i - 1]);
    }
  }
  cout << dp1[n][t - s] << endl;
}

Error: MLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define reep(n1, n2, n3) for (int n1 = n3; n1 < n2; n1++)
#define rep(n1, n2) reep(n1, n2, 0)
#define pb push_back
#define mp make_pair
#define fr first
#define sc second
#define INF 1e9
using namespace std;
typedef long long int lint;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<pair<int, int>> vp;
typedef pair<int, int> pi2;
typedef pair<int, pair<int, int>> pi3;
typedef vector<string> vs;
typedef pair<double, double> pdd;
const double PI = acos(-1.0);
int dp1[3010][3010];
int dp2[3010][3010];
int fn[3010];
int co[3010];
int main() {
  int n, t, s;
  cin >> n >> t >> s;
  rep(i, n) {
    cin >> fn[i];
    cin >> co[i];
  }
  reep(i, n + 1, 1) {
    reep(j, s + 1, 1) {
      dp1[i][j] = max(dp1[i][j - 1], dp1[i - 1][j]);
      if (co[i - 1] <= j)
        dp1[i][j] = max(dp1[i][j], dp1[i - 1][j - co[i - 1]] + fn[i - 1]);
    }
  }
  rep(i, n + 1) dp2[i][0] = dp1[i][s];
  reep(i, n + 1, 1) {
    reep(j, t - s + 1, 1) {
      dp2[i][j] = max(dp2[i][j - 1], dp2[i - 1][j]);
      if (co[i - 1] <= j)
        dp2[i][j] = max(dp2[i][j], dp2[i - 1][j - co[i - 1]] + fn[i - 1]);
    }
  }
  cout << dp2[n][t - s] << endl;
}
Problem p00496 (C++) — buggy submission, verdict: Memory Limit Exceeded

#include <algorithm>
#include <iostream>
using namespace std;
int dp[3200][3200], a[3200], b[3200];
signed main() {
  int n, t, s;
  cin >> n >> t >> s;
  for (int i = 1; i <= n; i++)
    cin >> a[i] >> b[i];

  int ans = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= t; j++) {
      dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
      if (j >= b[i] && (j - b[i] >= s || j <= s))
        dp[i][j] = max(dp[i - 1][j - b[i]] + a[i], dp[i][j]);
      ans = max(ans, dp[i][j]);
    }
  }
  cout << ans << endl;
}

Error: MLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <string>
using namespace std;
typedef long long LL;
#define INF -1e10
LL dp[3200][3200];
LL a[3200], b[3200];
int main() {
  int n, t, s;
  cin >> n >> t >> s;
  for (int i = 0; i < n; i++)
    cin >> a[i] >> b[i];

  for (int i = 0; i <= n; i++) {
    for (int j = 0; j <= t; j++) {
      dp[i][j] = INF;
    }
  }

  dp[0][0] = 0;
  dp[0][s] = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j <= s; j++) {
      if (dp[i - 1][j] == INF)
        continue;
      dp[i][j] = max(dp[i - 1][j], dp[i][j]);
      if (b[i - 1] + j <= s) {
        dp[i][j + b[i - 1]] = max(dp[i][j + b[i - 1]], dp[i - 1][j] + a[i - 1]);
      }
    }
  }

  for (int i = 1; i <= n; i++) {
    for (int j = 0; j <= s; j++) {
      dp[i][s] = max(dp[i][s], dp[i][j]);
    }
  }

  for (int i = 1; i <= n; i++) {
    for (int j = s; j <= t; j++) {
      if (dp[i - 1][j] == INF)
        continue;
      dp[i][j] = max(dp[i][j], dp[i - 1][j]);
      if (b[i - 1] + j <= t) {
        dp[i][j + b[i - 1]] = max(dp[i][j + b[i - 1]], dp[i - 1][j] + a[i - 1]);
      }
    }
  }

  LL ans = 0;
  for (int i = 0; i <= t; i++)
    ans = max(ans, dp[n][i]);
  cout << ans << endl;
  return 0;
}
Problem p00496 (C++) — buggy submission, verdict: Memory Limit Exceeded

#include <bits/stdc++.h>
using namespace std;

#define rep(i, x, y) for (int i = (x); i < (y); ++i)
#define mp(a, b) make_pair((a), (b))
#define debug(x) #x << "=" << (x)

#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define dump(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define dump(x)
#endif

typedef long long int ll;
typedef pair<int, int> pii;
// template<typename T> using vec=std::vector<T>;

const int INF = 1 << 30;
const long long int INF_ = 1LL << 58;
const double EPS = 1e-9;
const int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) {
  os << "[";
  for (const auto &v : vec) {
    os << v << ",";
  }
  os << "]";
  return os;
}

void Solve() {
  int n, t, s;
  cin >> n >> t >> s;

  vector<int> a(n), b(n);
  rep(i, 0, n) cin >> a[i] >> b[i];

  static int dp[3000][3001];
  int ans = 0;
  rep(i, 0, n) {
    rep(j, 0, t + 1) {
      if (i != 0)
        dp[i][j] = dp[i - 1][j];
      if (j - b[i] >= 0 && !(j - b[i] < s && s < j)) {
        if (i != 0)
          dp[i][j] = max(dp[i][j], dp[i - 1][j - b[i]] + a[i]);
        else
          dp[i][j] = a[i];
      }
      ans = max(ans, dp[i][j]);
    }
  }

  cout << ans << endl;
}

int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  Solve();
  return 0;
}

Error: MLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;

#define rep(i, x, y) for (int i = (x); i < (y); ++i)
#define mp(a, b) make_pair((a), (b))
#define debug(x) #x << "=" << (x)

#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define dump(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define dump(x)
#endif

typedef long long int ll;
typedef pair<int, int> pii;
// template<typename T> using vec=std::vector<T>;

const int INF = 1 << 30;
const long long int INF_ = 1LL << 58;
const double EPS = 1e-9;
const int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) {
  os << "[";
  for (const auto &v : vec) {
    os << v << ",";
  }
  os << "]";
  return os;
}

void Solve() {
  int n, t, s;
  cin >> n >> t >> s;

  vector<int> a(n), b(n);
  rep(i, 0, n) cin >> a[i] >> b[i];

  static ll dp[3000][3001];
  ll ans = 0;
  rep(i, 0, n) {
    rep(j, 0, t + 1) {
      if (i != 0)
        dp[i][j] = dp[i - 1][j];
      if (j - b[i] >= 0 && !(j - b[i] < s && s < j)) {
        if (i != 0)
          dp[i][j] = max(dp[i][j], dp[i - 1][j - b[i]] + a[i]);
        else
          dp[i][j] = a[i];
      }
      ans = max(ans, dp[i][j]);
    }
  }

  cout << ans << endl;
}

int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  Solve();
  return 0;
}
Problem p00496 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <iostream>
using namespace std;

int main() {
  int n;
  int t;
  int s;
  int tim[3001];
  int fun[3001];
  cin >> n >> t >> s;
  int nmax = n + 10;
  int tmax = t + 10;
  int **dp1;
  int **dp2;
  dp1 = new int *[nmax];
  for (int i = 0; i < nmax; i++)
    dp1[i] = new int[tmax];

  dp2 = new int *[nmax];
  for (int i = 0; i < nmax; i++)
    dp2[i] = new int[tmax];

  for (int i = 0; i < n; i++)
    cin >> fun[i] >> tim[i];
  for (int i = tim[0]; i <= s; i++)
    dp1[0][i] = fun[0];
  for (int i = tim[n - 1] + s; i <= t; i++)
    dp2[n - 1][i] = fun[n - 1];
  for (int k = 1; k < n; k++) {
    for (int i = 0; i <= s; i++) {
      if (i - tim[k] < 0) {
        dp1[k][i] = dp1[max(k - 1, 0)][i];
        continue;
      }

      dp1[k][i] =
          max(dp1[max(k - 1, 0)][i], dp1[max(k - 1, 0)][i - tim[k]] + fun[k]);
    }
  }
  for (int k = n - 2; k >= 0; k--) {
    for (int i = s; i <= t; i++) {
      if (i - tim[k] < s) {
        dp2[k][i] = dp2[min(k + 1, n - 1)][i];
        continue;
      }
      dp2[k][i] = max(dp2[min(k + 1, n - 1)][i],
                      dp2[min(k + 1, n - 1)][max(i - tim[k], 0)] + fun[k]);
    }
  }
  int ans = 0;
  int x = 0;
  int y = 0;
  for (int i = 0; i < n - 1; i++) {
    x = 0;
    y = 0;
    for (int k = 0; k <= s; k++)
      x = max(x, dp1[i][k]);
    for (int k = s; k <= t; k++)
      y = max(y, dp2[i + 1][k]);
    ans = max(ans, x + y);
  }
  cout << ans << endl;
  for (int i = 0; i < nmax; i++) {
    delete[] dp1[i];
    delete[] dp2[i];
  }
  delete[] dp1;
  delete[] dp2;
}

Error: -11

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <iostream>
using namespace std;

int main() {
  int n;
  int t;
  int s;
  int tim[3001];
  int fun[3001];
  cin >> n >> t >> s;
  int nmax = n + 10;
  int tmax = t + 10;
  int *dp1[nmax];
  int *dp2[nmax];
  for (int i = 0; i < n; i++)
    cin >> fun[i] >> tim[i];
  for (int i = tim[0]; i <= s; i++)
    dp1[0][i] = fun[0];
  for (int i = tim[n - 1] + s; i <= t; i++)
    dp2[n - 1][i] = fun[n - 1];
  for (int k = 1; k < n; k++) {
    for (int i = 0; i <= s; i++) {
      if (i - tim[k] < 0) {
        dp1[k][i] = dp1[max(k - 1, 0)][i];
        continue;
      }

      dp1[k][i] =
          max(dp1[max(k - 1, 0)][i], dp1[max(k - 1, 0)][i - tim[k]] + fun[k]);
    }
  }
  for (int k = n - 2; k >= 0; k--) {
    for (int i = s; i <= t; i++) {
      if (i - tim[k] < s) {
        dp2[k][i] = dp2[min(k + 1, n - 1)][i];
        continue;
      }
      dp2[k][i] = max(dp2[min(k + 1, n - 1)][i],
                      dp2[min(k + 1, n - 1)][max(i - tim[k], 0)] + fun[k]);
    }
  }
  int ans = 0;
  int x = 0;
  int y = 0;
  for (int i = 0; i < n - 1; i++) {
    x = 0;
    y = 0;
    for (int k = 0; k <= s; k++)
      x = max(x, dp1[i][k]);
    for (int k = s; k <= t; k++)
      y = max(y, dp2[i + 1][k]);
    ans = max(ans, x + y);
  }
  cout << ans << endl;
}