Language: C++

#include <algorithm>
#include <cstdio>
const int MAXN = 3005;
int A[MAXN];
int B[MAXN];
int dp[MAXN][MAXN];
int pd[MAXN][MAXN];
int N, T;

void copy(int i, int j, int prev) {
    dp[i][j] = dp[k][prev][j];
}

void augment(int k, int i, int j, int prev) {
    if (j >= 1) {
        dp[k][i][j] = std::max(dp[k][i][j-1], dp[k][i][j]);
    }
    if (j >= A[i]) {
        dp[k][i][j] = std::max(dp[k][prev][j - A[i]] + B[i], dp[k][i][j]);
    }
}

void prefix() {
    for (int j = 0; j <= T; ++j) {
        dp[0][j] = 0;
    }
    for (int i = 1; i <= N; ++i) {
        for (int j = 0; j <= T; ++j) {
            dp[i][j] = dp[i-1][j];
            if (j >= 1) {
                dp[i][j] = std::max(dp[i][j-1], dp[i][j]);
            }
            if (j >= A[i]) {
                dp[i][j] = std::max(dp[i-1][j - A[i]] + B[i], dp[i][j]);
            }
        }
    }
    for (int i = N; i >= 1; --i) {
        for (int j = 0; j <= T; ++j) {
            copy(1, i, j, i+1);
            augment(1, i, j, i+1);
        }
    }
}

void suffix() {
    for (int j = 0; j <= T; ++j) {
        pd[0][j] = 0;
    }
    for (int i = N; i >= 1; --i) {
        for (int j = 0; j <= T; ++j) {
            dp[i][j] = dp[i-1][j];
            if (j >= 1) {
                dp[i][j] = std::max(dp[i][j-1], dp[i][j]);
            }
            if (j >= A[i]) {
                dp[i][j] = std::max(dp[i-1][j - A[i]] + B[i], dp[i][j]);
            }
        }
    }
}

int solve() {
    prefix();
    suffix();
    // No final dish
    int ret = dp[0][N][T];
    // Fix final dish
    for (int i = 1; i <= N; ++i) {
        int cur = 0;
        for (int j = 0; j < T; ++j) {
            cur = std::max(dp[0][i-1][j] + dp[1][i+1][T-j-1], cur);
        }
        cur += B[i];
        ret = std::max(cur, ret);
    }
    return ret;
}

int main() {
    scanf(" %d%d", &N, &T);
    for (int i = 1; i <= N; ++i) {
        scanf(" %d%d", &A[i], &B[i]);
    }
    printf("%d\n", solve());
    return 0;
}

Compiler output:
a.cc: In function 'void copy(int, int, int)':
a.cc:11:19: error: 'k' was not declared in this scope
   11 |     dp[i][j] = dp[k][prev][j];
      |                   ^
a.cc: In function 'void augment(int, int, int, int)':
a.cc:16:17: error: invalid types 'int[int]' for array subscript
   16 |         dp[k][i][j] = std::max(dp[k][i][j-1], dp[k][i][j]);
      |                 ^
a.cc:16:40: error: invalid types 'int[int]' for array subscript
   16 |         dp[k][i][j] = std::max(dp[k][i][j-1], dp[k][i][j]);
      |                                        ^
a.cc:16:55: error: invalid types 'int[int]' for array subscript
   16 |         dp[k][i][j] = std::max(dp[k][i][j-1], dp[k][i][j]);
      |                                                       ^
a.cc:19:17: error: invalid types 'int[int]' for array subscript
   19 |         dp[k][i][j] = std::max(dp[k][prev][j - A[i]] + B[i], dp[k][i][j]);
      |                 ^
a.cc:19:43: error: invalid types 'int[int]' for array subscript
   19 |         dp[k][i][j] = std::max(dp[k][prev][j - A[i]] + B[i], dp[k][i][j]);
      |                                           ^
a.cc:19:70: error: invalid types 'int[int]' for array subscript
   19 |         dp[k][i][j] = std::max(dp[k][prev][j - A[i]] + B[i], dp[k][i][j]);
      |                                                                      ^
a.cc: In function 'void prefix()':
a.cc:40:17: error: too many arguments to function 'void copy(int, int, int)'
   40 |             copy(1, i, j, i+1);
      |             ~~~~^~~~~~~~~~~~~~
a.cc:10:6: note: declared here
   10 | void copy(int i, int j, int prev) {
      |      ^~~~
a.cc: In function 'int solve()':
a.cc:67:23: error: invalid types 'int[int]' for array subscript
   67 |     int ret = dp[0][N][T];
      |                       ^
a.cc:72:38: error: invalid types 'int[int]' for array subscript
   72 |             cur = std::max(dp[0][i-1][j] + dp[1][i+1][T-j-1], cur);
      |                                      ^
a.cc:72:54: error: invalid types 'int[int]' for array subscript
   72 |             cur = std::max(dp[0][i-1][j] + dp[1][i+1][T-j-1], cur);
      |                                                      ^