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

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

int main() {
  int a, b;
  static int A[5000], B[5000], dp[2][5001];
  scanf("%d %d", &a, &b);
  for (int i = 0; i < a; i++)
    scanf("%d", A + i);
  for (int i = 0; i < b; i++)
    scanf("%d", B + i);
  for (int i = 0; i <= a; i++) {
    for (int j = 0; j <= b; j++) {
      if (i == 0 || j == 0)
        dp[i % 2][j] = 0;
      else if (A[i - 1] == B[j - 1]) {
        dp[i % 2][j] = max(dp[(i - 1) % 2][j], dp[(i - 1) % 2][j - 1] + 1);
      } else {
        dp[i % 2][j] = dp[(i - 1) % 2][j];
      }
    }
  }
  int ans = 0;
  for (int i = 0; i <= b; i++)
    ans = max(ans, dp[a % 2][i]);
  printf("%d\\n", ans);
  return 0;
}

Error: MLE

Fixed submission:

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

int main() {
  int a, b;
  static int A[5000], B[5000], dp[5001][5001];
  scanf("%d %d", &a, &b);
  for (int i = 0; i < a; i++)
    scanf("%d", A + i);
  for (int i = 0; i < b; i++)
    scanf("%d", B + i);
  for (int i = 0; i <= a; i++) {
    for (int j = 0; j <= b; j++) {
      if (i == 0 || j == 0)
        dp[i][j] = 0;
      else if (A[i - 1] == B[j - 1]) {
        dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - 1] + 1);
      } else {
        dp[i][j] = dp[i - 1][j];
      }
    }
  }
  int ans = 0;
  for (int i = 0; i <= b; i++)
    ans = max(ans, dp[a][i]);
  printf("%d\\n", ans);
  return 0;
}
Problem p00496 (C++) — buggy submission, verdict: Memory Limit Exceeded

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

int dp[4000][5000];
int a[4000], b[4000], n, t, s, maxn;
int main() {
  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 + 1][j] = max(dp[i + 1][j], dp[i][j]);
      if ((j + b[i] <= s || j >= s) && j + b[i] <= t) {
        dp[i + 1][j + b[i]] = max(dp[i + 1][j + b[i]], dp[i][j] + a[i]);
      }
    }
  }
  for (int i = 0; i <= t; i++) {
    maxn = max(maxn, dp[n][i]);
  }
  cout << maxn << endl;
  return 0;
}

Error: MLE

Fixed submission:

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

int dp[3000][10000];
int a[3000], b[3000], n, t, s, maxn;
int main() {
  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 + 1][j] = max(dp[i + 1][j], dp[i][j]);
      if (j + b[i] <= s || j >= s) {
        dp[i + 1][j + b[i]] = max(dp[i + 1][j + b[i]], dp[i][j] + a[i]);
      }
    }
  }
  for (int i = 0; i <= t; i++) {
    maxn = max(maxn, dp[n][i]);
  }
  cout << maxn << endl;
  return 0;
}
Problem p00496 (C++) — buggy submission, verdict: Memory Limit Exceeded

#include <algorithm>
#include <iostream>

using namespace std;
typedef long long ll;

int N, S, T;
int A[3000], B[3000];
int dp[3010][3010];

int main() {
  cin >> N >> T >> S;
  for (int i = 0; i < N; i++) {
    cin >> A[i] >> B[i];
  }

  dp[0][0] = 0;
  if (B[0] <= S && B[0] < T)
    dp[B[0]][1] = A[0];

  for (int i = 0; i <= T; i++) {
    for (int j = 0; j < N; j++) {
      if (i != T)
        dp[i + 1][j] = max(dp[i][j], dp[i + 1][j]);
      dp[i][j + 1] = max(dp[i][j], dp[i][j + 1]);
      if (i + B[j] <= T && ((i <= S && i + B[j] <= S) || (S <= i)))
        dp[i + B[j]][j + 1] = max(dp[i + B[j]][j + 1], dp[i][j] + A[j]);
    }
  }
  cout << dp[T][N] << endl;
  return 0;
}

Error: MLE

Fixed submission:

#include <algorithm>
#include <iostream>

using namespace std;
typedef long long ll;

int N, S, T;
ll A[3000], B[3000];
ll dp[3001][3001];

int main() {
  cin >> N >> T >> S;
  for (int i = 0; i < N; i++) {
    cin >> A[i] >> B[i];
  }

  dp[0][0] = 0;
  if (B[0] <= S && B[0] < T)
    dp[B[0]][1] = A[0];

  for (int i = 0; i < T - 1; i++) {
    for (int j = 0; j < N; j++) {
      dp[i + 1][j] = max(dp[i][j], dp[i + 1][j]);
      dp[i][j + 1] = max(dp[i][j], dp[i][j + 1]);
      if (((i <= S && i + B[j] <= S) || (S <= i)) && i + B[j] < T)
        dp[i + B[j]][j + 1] = max(dp[i + B[j]][j + 1], dp[i][j] + A[j]);
    }
  }
  ll ans = 0;
  for (int i = 0; i <= N; i++)
    ans = max(ans, dp[T - 1][i]);
  cout << ans << endl;
  return 0;
}
Problem p00496 (C++) — buggy submission, verdict: Memory Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef double ld;
#define X first
#define Y second
#define mk make_pair
#define pb push_back
#define Rep(i, n) for (int i = 0; i < int(n); i++)
#define Rep1(i, n) for (int i = 1; i <= int(n); i++)
#define all(x) (x).begin(), (x).end()
const int MOD = (int)1e9 + 7;
const ll base = 31;
void MAIN();
int main() {
  // freopen("input.txt", "r", stdin);
  ios::sync_with_stdio(false);
  cin.tie(0);
  MAIN();
  return 0;
}
////////////////////////////////////////////////////////////////////////

const int N = 3004;

int n, t, s, f[N][N], g[N];
int a[N], b[N];

void MAIN() {
  cin >> n >> t >> s;
  Rep1(i, n) cin >> a[i] >> b[i];

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

Error: MLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef double ld;
#define X first
#define Y second
#define mk make_pair
#define pb push_back
#define Rep(i, n) for (int i = 0; i < int(n); i++)
#define Rep1(i, n) for (int i = 1; i <= int(n); i++)
#define all(x) (x).begin(), (x).end()
const int MOD = (int)1e9 + 7;
const ll base = 31;
void MAIN();
int main() {
  // freopen("input.txt", "r", stdin);
  ios::sync_with_stdio(false);
  cin.tie(0);
  MAIN();
  return 0;
}
////////////////////////////////////////////////////////////////////////

const int N = 3004;

int n, t, s, f[N][N], g[N][N];
int a[N], b[N];

void MAIN() {
  cin >> n >> t >> s;
  Rep1(i, n) cin >> a[i] >> b[i];

  for (int i = 1; i <= n; i++) {
    for (int j = 0; j <= s; j++) {
      f[i][j] = f[i - 1][j];
      if (j >= b[i])
        f[i][j] = max(f[i][j], f[i - 1][j - b[i]] + a[i]);
    }
  }
  for (int i = n; i >= 1; i--) {
    for (int j = 0; j <= t - s; j++) {
      g[i][j] = g[i + 1][j];
      if (j >= b[i])
        g[i][j] = max(g[i][j], g[i + 1][j - b[i]] + a[i]);
    }
  }
  int ans = 0;
  for (int i = 0; i <= n; i++)
    ans = max(ans, f[i][s] + g[i + 1][t - s]);
  cout << ans << endl;
}
Problem p00496 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, j) FOR(i, 0, j)

const int INF = 1 << 24;
const int dx[4] = {0, 0, 1, -1}, dy[4] = {1, -1, 0, 0};

typedef unsigned long long ull;

int N, T, S;
int A[3000], B[3000], dp[3000][3001];

int main() {
  std::cin >> N >> T >> S;

  REP(i, N) { std::cin >> A[i] >> B[i]; }

  REP(i, T + 1) { dp[0][i] = 0; }

  REP(i, T + 1) {
    if (i + B[0] <= T && (i + B[0] <= S || S <= i)) {
      dp[0][i + B[0]] = A[0];
    }
  }

  REP(i, N - 1) {
    REP(j, T + 1) {
      dp[i + 1][j] = std::max(dp[i + 1][j], dp[i][j]);
      if (j + B[i + 1] <= T && (j + B[i + 1] <= S || S <= j)) {
        dp[i + 1][j + B[i + 1]] =
            std::max(dp[i + 1][j + B[i + 1]], dp[i][j] + A[i + 1]);
      }
    }
  }

  int res = 0;
  REP(i, T + 1) { res = std::max(res, dp[N - 1][i]); }

  std::cout << res << std::endl;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, j) FOR(i, 0, j)

const int INF = 1 << 24;
const int dx[4] = {0, 0, 1, -1}, dy[4] = {1, -1, 0, 0};

typedef unsigned long long ull;

int N, T, S;
int A[3010], B[3010], dp[3010][3010];

int rec(int index, int t) {
  if (t >= T) {
    return 0;
  }

  if (index >= N) {
    return 0;
  }

  if (dp[index][t] != -1) {
    return dp[index][t];
  }

  int res = rec(index + 1, t);
  FOR(i, index, N) {
    if (t < S) {
      if (t + B[index] <= S) {
        res = std::max(res, rec(index + 1, t + B[index]) + A[index]);
      }
    } else {
      if (t + B[index] <= T) {
        res = std::max(res, rec(index + 1, t + B[index]) + A[index]);
      }
    }
  }

  return dp[index][t] = res;
}

int main() {
  std::cin >> N >> T >> S;

  REP(i, N) {
    std::cin >> A[i];
    std::cin >> B[i];
  }

  REP(i, N) {
    REP(j, T + 1) { dp[i][j] = -1; }
  }

  int res = 0;
  REP(i, T + 1) {
    REP(j, N) { res = std::max(res, rec(j, i)); }
  }

  std::cout << res << std::endl;
}
Problem p00496 (C++) — buggy submission, verdict: Memory Limit Exceeded

#include <bits/stdc++.h>
#define foru(i, a, b) for (int i = int(a); i <= int(b); i++)
#define ford(i, a, b) for (int i = int(a); i >= int(b); i--)
using namespace std;

const int N = 3005;

int n, t, s, a[N], b[N];
int f1[N][N], luu[N], maxx[N];

int main() {
  // freopen("a.txt", "r", stdin);

  scanf("%d%d%d", &n, &t, &s);
  foru(i, 1, n) scanf("%d%d", &a[i], &b[i]);
  /// xuoi
  foru(j, 0, t) maxx[j] = 0;
  foru(i, 1, n) {
    foru(j, 0, t) {
      f1[i][j] = f1[i - 1][j];
      if (j >= b[i])
        f1[i][j] = max(f1[i][j], maxx[j - b[i]] + a[i]);
    }
    foru(j, 0, t) {
      maxx[j] = max(maxx[j], f1[i][j]);
      if (j)
        maxx[j] = max(maxx[j], maxx[j - 1]);
    }
  }
  foru(i, 1, n) {
    luu[i] = f1[i][s];
    foru(j, 0, t) f1[i][j] = 0;
  }
  /// nguoc
  foru(j, 0, t) maxx[j] = 0;
  ford(i, n, 1) {
    ford(j, t, 0) {
      f1[i][j] = f1[i + 1][j];
      if (j + b[i] <= t)
        f1[i][j] = max(f1[i][j], maxx[j + b[i]] + a[i]);
    }
    ford(j, t, 0) {
      maxx[j] = max(maxx[j], f1[i][j]);
      if (j < t)
        maxx[j] = max(maxx[j], maxx[j + 1]);
    }
  }

  int ans = 0;
  foru(i, 1, n) ans = max(ans, luu[i] + f1[i + 1][s]);
  cout << ans << endl;
}

Error: MLE

Fixed submission:

#include <bits/stdc++.h>
#define foru(i, a, b) for (int i = int(a); i <= int(b); i++)
#define ford(i, a, b) for (int i = int(a); i >= int(b); i--)
using namespace std;

const int N = 3005;

int n, t, s, a[N], b[N];
int f1[N][N], f2[N][N], maxx[N];

int main() {
  // freopen("a.txt", "r", stdin);

  scanf("%d%d%d", &n, &t, &s);
  foru(i, 1, n) scanf("%d%d", &a[i], &b[i]);
  /// xuoi
  foru(j, 0, t) maxx[j] = 0;
  foru(i, 1, n) {
    foru(j, 0, t) {
      f1[i][j] = f1[i - 1][j];
      if (j >= b[i])
        f1[i][j] = max(f1[i][j], maxx[j - b[i]] + a[i]);
    }
    foru(j, 0, t) {
      maxx[j] = max(maxx[j], f1[i][j]);
      if (j)
        maxx[j] = max(maxx[j], maxx[j - 1]);
    }
  }
  /// nguoc
  foru(j, 0, t) maxx[j] = 0;
  ford(i, n, 1) {
    ford(j, t, 0) {
      f2[i][j] = f2[i + 1][j];
      if (j + b[i] <= t)
        f2[i][j] = max(f2[i][j], maxx[j + b[i]] + a[i]);
    }
    ford(j, t, 0) {
      maxx[j] = max(maxx[j], f2[i][j]);
      if (j < t)
        maxx[j] = max(maxx[j], maxx[j + 1]);
    }
  }

  int ans = 0;
  foru(i, 1, n) ans = max(ans, f1[i][s] + f2[i + 1][s]);
  cout << ans << endl;
}
Problem p00496 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

using namespace std;

#define REP(i, a, b) for (int i = a; i < b; i++)
#define rep(i, n) REP(i, 0, n)

#define chmax(a, x) a = max(a, x)

typedef long long ll;

int N, S, T;
ll dp[2][3100], ans;
ll A[3100], B[3100];

int main() {

  cin >> N >> T >> S;
  rep(i, N) cin >> A[i] >> B[i];

  rep(i, N) rep(j, T + 1) {
    chmax(dp[(i + 1) & 1][j], dp[i & 1][j]);
    if (j + B[i] <= T) {
      if (j < S && S < j + B[i])
        continue;
      chmax(dp[(i + 1) & 1][j + B[i]], dp[i & 1][j] + A[i]);
      chmax(ans, dp[(i + 1) & 1][j + B[i]]);
    }
  }

  cout << ans << endl;

  return 0;
}

Error: 0

Fixed submission:

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

#define MAX_T 3001

int main() {
  int n, t, s;
  int a, b;

  cin >> n >> t >> s;

  vector<long long> dp(n);

  for (int i = 0; i < n; i++) {
    cin >> a >> b;
    for (int j = i; j < b; j++)
      dp[j] += a;
  }

  cout << *max_element(dp.begin(), dp.end()) - 4 << endl;

  return 0;
}
Problem p00496 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cstdio>
#include <vector>
using namespace std;

static int dp[3010][3010];
const int inf = (int)1e9;

int solve(int n, int t, int s, vector<int> &a, vector<int> &b) {
  if (t < 0)
    return -inf;
  if (n < 0)
    return 0;
  if (dp[n][t] != -1)
    return dp[n][t];
  int ans = 0;
  int temp;

  temp = solve(n - 1, t, s, a, b);
  ans = max(temp, ans);
  bool cross = s < t && t - b[n] < s;
  if (cross)
    temp = solve(n, s, s, a, b);
  else
    temp = solve(n - 1, t - b[n], s, a, b) + a[n];
  ans = max(temp, ans);
  return dp[n][t] = ans;
}

int main() {
  int n, t, s;
  vector<int> a, b;
  scanf("%d%d%d", &n, &t, &s);
  a.resize(n);
  b.resize(n);
  for (int i = 0; i < n; ++i)
    scanf("%d%d", &a[i], &b[i]);
  fill(dp[0], dp[3010], -1);
  int ans = solve(n - 1, t, s, a, b);
  printf("%d\\n", ans);
  return 0;
}

Error: -11

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <vector>
using namespace std;

static int dp[3010][3010];
const int inf = (int)1e9;

int solve(int n, int t, int s, vector<int> &a, vector<int> &b) {
  if (t < 0)
    return -inf;
  if (n < 0)
    return 0;
  if (dp[n][t] != -1)
    return dp[n][t];
  int ans = 0;
  int temp;

  temp = solve(n - 1, t, s, a, b);
  ans = max(temp, ans);
  bool cross = s < t && t - b[n] < s;
  if (cross)
    temp = solve(n, s, s, a, b);
  else
    temp = solve(n - 1, t - b[n], s, a, b);
  ans = max(temp, ans);
  return dp[n][t] = ans;
}

int main() {
  int n, t, s;
  vector<int> a, b;
  scanf("%d%d%d", &n, &t, &s);
  for (int i = 0; i < n; ++i)
    scanf("%d%d", &a[i], &b[i]);
  fill(dp[0], dp[3010], -1);
  int ans = solve(n - 1, t, s, a, b);
  printf("%d\\n", ans);
  return 0;
}
Problem p00496 (C++) — buggy submission, verdict: Memory Limit Exceeded

#include <stdio.h>
int a, b, c, d[3001], e[3001], f[3001][3001], i, j, m = 0, k;
int main(void) {
  scanf("%d %d %d", &a, &b, &c);
  for (i = 0; i < a; i++) {
    scanf("%d %d", &d[i], &e[i]);
  }
  for (i = 0; i <= a; i++) {
    for (j = 0; j <= b; j++) {
      f[i][j] = -1;
    }
  }
  f[0][0] = 0;
  for (i = 0; i < a; i++) {
    for (j = 0; j <= b; j++) {
      if (f[i][j] != -1) {
        if (j < c && c < e[i] + j) {
          if (b >= c + e[i]) {
            if (f[i + 1][c + e[i]] < f[i][j] + d[i]) {
              f[i + 1][c + e[i]] = f[i][j] + d[i];
            }
          }
          if (f[i][j] > f[i + 1][j]) {
            f[i + 1][j] = f[i][j];
          }
        } else {
          if (f[i][j] + d[i] > f[i + 1][j + e[i]]) {
            if (j + e[i] <= b) {
              f[i + 1][j + e[i]] = f[i][j] + d[i];
            }
          }
          if (f[i][j] > f[i + 1][j]) {
            f[i + 1][j] = f[i][j];
          }
        }
      }
    }
  }
  for (i = 0; i <= b; i++) {
    if (m < f[a][i]) {
      m = f[a][i];
    }
  }
  printf("%d\\n", m);
  return 0;
}

Error: MLE

Fixed submission:

#include <stdio.h>
long long int a, b, c, d[3001], e[3001], f[3001][3001], i, j, m = 0, k;
int main(void) {
  scanf("%lld %lld %lld", &a, &b, &c);
  for (i = 0; i < a; i++) {
    scanf("%lld %lld", &d[i], &e[i]);
  }
  for (i = 0; i <= a; i++) {
    for (j = 0; j <= b; j++) {
      f[i][j] = -1;
    }
  }
  f[0][0] = 0;
  for (i = 0; i < a; i++) {
    for (j = 0; j <= b; j++) {
      if (f[i][j] != -1) {
        if (j <= c && c <= e[i] + j && b >= c + e[i]) {
          if (f[i + 1][c + e[i]] < f[i][j] + d[i]) {
            f[i + 1][c + e[i]] = f[i][j] + d[i];
          }
          if (f[i][j] > f[i + 1][j]) {
            f[i + 1][j] = f[i][j];
          }
        } else {
          if (f[i][j] + d[i] > f[i + 1][j + e[i]]) {
            if (j + e[i] <= b) {
              f[i + 1][j + e[i]] = f[i][j] + d[i];
            }
          }
          if (f[i][j] > f[i + 1][j]) {
            f[i + 1][j] = f[i][j];
          }
        }
      }
    }
  }
  for (i = 0; i <= b; i++) {
    if (m < f[a][i]) {
      m = f[a][i];
    }
  }
  printf("%lld\\n", m);
  return 0;
}
Problem p00496 (C++) — buggy submission, verdict: Runtime Error

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

template <typename T> vector<T> make_v(size_t a) { return vector<T>(a); }
template <typename T> vector<vector<T>> make_v(size_t a, size_t b) {
  return vector<vector<T>>(a, make_v<T>(b));
}
template <typename T>
vector<vector<vector<T>>> make_v(size_t a, size_t b, size_t c) {
  return vector<vector<vector<T>>>(a, make_v<T>(b, c));
}

template <typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type fill_v(T &t, const V &v) {
  t = v;
}

template <typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type fill_v(T &t, const V &v) {
  for (auto &e : t)
    fill_v(e, v);
}

template <typename T> void chmin(T &a, T b) {
  if (a > b)
    a = b;
}
template <typename T> void chmax(T &a, T b) {
  if (a < b)
    a = b;
}

// INSERT ABOVE HERE
signed main() {
  Int n, t, s;
  cin >> n >> t >> s;
  vector<Int> a(n), b(n);
  for (Int i = 0; i < n; i++)
    cin >> a[i] >> b[i];
  auto dp = make_v<Int>(t + 3333);
  const Int INF = 1e12;
  fill_v(dp, -INF);
  dp[0] = 0;
  for (Int i = 0; i < n; i++) {
    for (Int j = t; j >= 0; j--) {
      if (dp[j] == -INF)
        continue;
      if (j + b[i] > t)
        continue;
      if (j < s && j + b[i] > s)
        chmax(dp[s + b[i]], dp[j] + a[i]);
      else
        chmax(dp[j + b[i]], dp[j] + a[i]);
    }
  }
  cout << *max_element(dp.begin(), dp.begin() + t + 1) << endl;
  return 0;
}


Error: 0

Fixed submission:

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

template <typename T> vector<T> make_v(size_t a) { return vector<T>(a); }
template <typename T> vector<vector<T>> make_v(size_t a, size_t b) {
  return vector<vector<T>>(a, make_v<T>(b));
}
template <typename T>
vector<vector<vector<T>>> make_v(size_t a, size_t b, size_t c) {
  return vector<vector<vector<T>>>(a, make_v<T>(b, c));
}

template <typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type fill_v(T &t, const V &v) {
  t = v;
}

template <typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type fill_v(T &t, const V &v) {
  for (auto &e : t)
    fill_v(e, v);
}

template <typename T> void chmin(T &a, T b) {
  if (a > b)
    a = b;
}
template <typename T> void chmax(T &a, T b) {
  if (a < b)
    a = b;
}

// INSERT ABOVE HERE
signed main() {
  Int n, t, s;
  cin >> n >> t >> s;
  vector<Int> a(n), b(n);
  for (Int i = 0; i < n; i++)
    cin >> a[i] >> b[i];
  auto dp = make_v<Int>(t + 1);
  const Int INF = 1e12;
  fill_v(dp, -INF);
  dp[0] = 0;
  for (Int i = 0; i < n; i++) {
    for (Int j = t; j >= 0; j--) {
      if (dp[j] == -INF)
        continue;
      if (j + b[i] > t)
        continue;
      if (j < s && j + b[i] > s)
        chmax(dp[s + b[i]], dp[j] + a[i]);
      else
        chmax(dp[j + b[i]], dp[j] + a[i]);
    }
  }
  cout << *max_element(dp.begin(), dp.end()) << endl;
  return 0;
}
Problem p00496 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int n, t, s;
int a[3001], b[3001];

int dp[3002][3001];
int ans;

int main() {
  scanf("%d %d %d", &n, &t, &s);
  for (int i = 1; i < n + 1; i++)
    scanf("%d %d", &a[i], &b[i]);

  for (int i = 1; i < n + 1; i++) {
    for (int j = 0; j < t + 1; j++) {
      if (s <= j - b[i] || j <= s) {
        if (j - b[i] >= 0)
          dp[i][j] = max(dp[i][j], dp[i - 1][j - b[i]] + a[i]);
      }
      dp[i + 1][j] = dp[i][j];
      ans = max(ans, dp[i][j]);
    }
  }
  /*
          for(int i=0; i<t+1; i++){
                  for(int j=0; j<n+1; j++){
                          printf("%d\\t", dp[j][i]);
                  }
                  printf("\\n");
          }
  */
  printf("%d\\n", ans);
}

Error: TLE

Fixed submission:

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

int n, t, s;
int a[3000], b[3000];

int dp[3001][3001];
int ans;

int main() {
  scanf("%d %d %d", &n, &t, &s);
  for (int i = 1; i < n + 1; i++)
    scanf("%d %d", &a[i], &b[i]);

  for (int i = 0; i < t; i++) {
    for (int j = 0; j < n + 1; j++) {
      for (int l = 0; l < j; l++) {
        if (s <= i - b[j] || i <= s) {
          if (i - b[j] >= 0) {
            dp[i][j] = max(dp[i][j], dp[i - b[j]][l] + a[j]);
            ans = max(ans, dp[i][j]);
          }
        }
      }
    }
  }
  /*
          for(int i=0; i<t; i++){
                  for(int j=0; j<n+1; j++){
                          printf("%d\\t", dp[i][j]);
                  }
                  printf("\\n");
          }
  */
  printf("%d\\n", ans);
}
Problem p00496 (C++) — buggy submission, verdict: Memory Limit Exceeded

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

typedef long long ll;
#define rep(i, n) for (int(i) = 0; (i) < (int)(n); ++(i))
#define each(itr, c)                                                           \\
  for (__typeof(c.begin()) itr = c.begin(); itr != c.end(); ++itr)
#define all(x) (x).begin(), (x).end()
#define mp make_pair
#define pb push_back
#define fi first
#define se second

//???i?????§??????????±???????,?????¨??????j
int dp[3010][3010] = {0};

int main() {
  int n, t, s;
  cin >> n >> t >> s;
  vector<int> a(n), b(n);
  rep(i, n) cin >> a[i] >> b[i];

  rep(i, n) {
    rep(j, t + 1) {
      //?????°??????
      dp[i + 1][j] = max(dp[i + 1][j], dp[i][j]);
      //?????¶
      int nx = j + b[i];
      if (nx > t || (j < s && s < nx))
        continue;
      dp[i + 1][nx] = max(dp[i + 1][nx], dp[i][j] + a[i]);
    }
  }

  int ans = 0;
  rep(i, t + 1) ans = max(ans, dp[n][i]);
  cout << ans << endl;
  return 0;
}

Error: MLE

Fixed submission:

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

typedef long long ll;
#define rep(i, n) for (int(i) = 0; (i) < (int)(n); ++(i))
#define each(itr, c)                                                           \\
  for (__typeof(c.begin()) itr = c.begin(); itr != c.end(); ++itr)
#define all(x) (x).begin(), (x).end()
#define mp make_pair
#define pb push_back
#define fi first
#define se second

ll dp[3001][3001] = {0};

int main() {
  int n, t, s;
  cin >> n >> t >> s;
  vector<int> a(n), b(n);
  rep(i, n) cin >> a[i] >> b[i];

  //???i????????????,??????j
  rep(i, n) {
    //??±??????
    rep(j, s) {
      //?????°??????
      dp[i + 1][j] = max(dp[i + 1][j], dp[i][j]);
      //?????¶
      int nx = j + b[i];
      if (nx > s)
        continue;
      dp[i + 1][nx] = max(dp[i + 1][nx], dp[i][j] + a[i]);
    }
    for (int j = s; j < t; ++j) {
      //?????°??????
      dp[i + 1][j] = max(dp[i + 1][j], dp[i][j]);
      //?????¶
      int nx = j + b[i];
      if (nx > t)
        continue;
      dp[i + 1][nx] = max(dp[i + 1][nx], dp[i][j] + a[i]);
    }
  }

  ll ans = 0;
  rep(i, t + 1) ans = max(ans, dp[n][i]);
  cout << ans << endl;
  return 0;
}