Language: C++

#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <sstream>
#include <algorithm>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <list>
#include <cstdio>
#include <iostream>
#include <cmath>
#include <climits>
#include <bitset>
#include <functional>
#include <numeric>
#include <ctime>
#include <cassert>
#include <cstring>
#include <fstream>
#include <iomanip>

using namespace std;

#define FOR(i, a, b) for(int (i)=(a);(i)<(b);(i)++)
#define IFOR(i, a, b) for(int (i)=(a);(i)<=(b);(i)++)
#define RFOR(i, a, b) for(int (i)=(a);(i)>=(b);(i)--)
#define REP(i, n) FOR((i), 0, (n))

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

template<class T>
void print_container(T &container, string delim=" ") {
    bool first = true;
    for(auto &t: container){
        if(!first){
            cout << delim;
        }
        first = false;
        cout << t;
    }
    cout << endl;
}

#define int long long;
signed main() {
    int n, t;
    cin >> n >> t;
    vector<pii> ab(n);
    REP(i, n){
        cin >> ab[i].first >> ab[i].second;
    }
    sort(ab.begin(), ab.end());

    vector<vector<int>> dp(n+1, vector<int>(6001, -1));
    dp[0][0] = 0;
    // onlyはjを実際に使う場合のみ更新
    vector<vector<int>> only(dp);

    IFOR(i, 1, n){
        RFOR(j, 6000, 0){
            dp[i][j] = dp[i-1][j];
            if(j-ab[i-1].first >= 0 && dp[i-1][j-ab[i-1].first] >= 0){
                if(dp[i][j] <= dp[i-1][j-ab[i-1].first] + ab[i-1].second){
                    dp[i][j] = dp[i-1][j-ab[i-1].first] + ab[i-1].second;
                    only[i][j] = dp[i][j];
                }
            }
        }
    }

    int ans = 0;
    IFOR(i, 1, n){
        int limit = t + ab[i-1].first - 1;
        IFOR(j, 0, limit){
            ans = max(ans, only[i][j]);
        }
    }

    cout << ans << endl;


    return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:50:18: error: declaration does not declare anything [-fpermissive]
   50 | #define int long long;
      |                  ^~~~
a.cc:52:5: note: in expansion of macro 'int'
   52 |     int n, t;
      |     ^~~
a.cc:52:9: error: 'n' was not declared in this scope; did you mean 'yn'?
   52 |     int n, t;
      |         ^
      |         yn
a.cc:52:12: error: 't' was not declared in this scope; did you mean 'tm'?
   52 |     int n, t;
      |            ^
      |            tm
a.cc:50:18: error: declaration does not declare anything [-fpermissive]
   50 | #define int long long;
      |                  ^~~~
a.cc:28:26: note: in expansion of macro 'int'
   28 | #define FOR(i, a, b) for(int (i)=(a);(i)<(b);(i)++)
      |                          ^~~
a.cc:31:19: note: in expansion of macro 'FOR'
   31 | #define REP(i, n) FOR((i), 0, (n))
      |                   ^~~
a.cc:55:5: note: in expansion of macro 'REP'
   55 |     REP(i, n){
      |     ^~~
a.cc:55:9: error: 'i' was not declared in this scope
   55 |     REP(i, n){
      |         ^
a.cc:28:31: note: in definition of macro 'FOR'
   28 | #define FOR(i, a, b) for(int (i)=(a);(i)<(b);(i)++)
      |                               ^
a.cc:55:5: note: in expansion of macro 'REP'
   55 |     REP(i, n){
      |     ^~~
a.cc:28:45: error: expected ')' before ';' token
   28 | #define FOR(i, a, b) for(int (i)=(a);(i)<(b);(i)++)
      |                         ~                   ^
a.cc:31:19: note: in expansion of macro 'FOR'
   31 | #define REP(i, n) FOR((i), 0, (n))
      |                   ^~~
a.cc:55:5: note: in expansion of macro 'REP'
   55 |     REP(i, n){
      |     ^~~
a.cc:55:9: error: 'i' was not declared in this scope
   55 |     REP(i, n){
      |         ^
a.cc:28:47: note: in definition of macro 'FOR'
   28 | #define FOR(i, a, b) for(int (i)=(a);(i)<(b);(i)++)
      |                                               ^
a.cc:55:5: note: in expansion of macro 'REP'
   55 |     REP(i, n){
      |     ^~~
a.cc:50:18: error: template argument 1 is invalid
   50 | #define int long long;
      |                  ^~~~
a.cc:60:19: note: in expansion of macro 'int'
   60 |     vector<vector<int>> dp(n+1, vector<int>(6001, -1));
      |                   ^~~
a.cc:50:18: error: template argument 2 is invalid
   50 | #define int long long;
      |                  ^~~~
a.cc:60:19: note: in expansion of macro 'int'
   60 |     vector<vector<int>> dp(n+1, vector<int>(6001, -1));
      |                   ^~~
a.cc:60:12: error: template argument 1 is invalid
   60 |     vector<vector<int>> dp(n+1, vector<int>(6001, -1));
      |            ^
a.cc:60:12: error: template argument 2 is invalid
a.cc:60:22: error: expected primary-expression before '>>' token
   60 |     vector<vector<int>> dp(n+1, vector<int>(6001, -1));
      |                      ^~
a.cc:50:18: error: template argument 1 is invalid
   50 | #define int long long;
      |                  ^~~~
a.cc:60:40: note: in expansion of macro 'int'
   60 |     vector<vector<int>> dp(n+1, vector<int>(6001, -1));
      |                                        ^~~
a.cc:50:18: error: template argument 2 is invalid
   50 | #define int long long;
      |                  ^~~~
a.cc:60:40: note: in expansion of macro 'int'
   60 |     vector<vector<int>> dp(n+1, vector<int>(6001, -1));
      |                                        ^~~
a.cc:60:43: error: expected primary-expression before '>' token
   60 |     vector<vector<int>> dp(n+1, vector<int>(6001, -1));
      |                                           ^
a.cc:61:5: error: 'dp' was not declared in this scope
   61 |     dp[0][0] = 0;
      |     ^~
a.cc:50:18: error: template argument 1 is invalid
   50 | #define int long long;
      |                  ^~~~
a.cc:63:19: note: in expansion of macro 'int'
   63 |     vector<vector<int>> only(dp);
      |                   ^~~
a.cc:50:18: error: template argument 2 is invalid
   50 | #define int long long;
      |                  ^~~~
a.cc:63:19: note: in expansion of macro 'int'
   63 |     vector<vector<int>> only(dp);
      |                   ^~~
a.cc:63:12: error: template argument 1 is invalid
   63 |     vector<vector<int>> only(dp);
      |            ^
a.cc:63:12: error: template argument 2 is invalid
a.cc:63:22: error: expected primary-expression before '>>' token
   63 |     vector<vector<int>> only(dp);
      |                      ^~
a.cc:63:25: error: 'only' was not declared in this scope
   63 |     vector<vector<int>> only(dp);
      |                         ^~~~
a.cc:50:18: error: declaration does not declare anything [-fpermissive]
   50 | #define int long long;
      |                  ^~~~
a.cc:29:27: note: in expansion of macro 'int'
   29 | #define IFOR(i, a, b) for(int (i)=(a);(i)<=(b);(i)++)
      |                           ^~~
a.cc:65:5: note: in expansion of macro 'IFOR'
   65 |     IFOR(i, 1, n){
      |     ^~~~
a.cc:29:47: error: expected ')' before ';' token
   29 | #define IFOR(i, a, b) for(int (i)=(a);(i)<=(b);(i)++)
      |                          ~                    ^
a.cc:65:5: note: in expansion of macro 'IFOR'
   65 |     IFOR(i, 1, n){
      |     ^~~~
a.cc:50:18: error: declaration does not declare anything [-fpermissive]
   50 | #define int long long;
      |                  ^~~~
a.cc:77:5: note: in expansion of macro 'int'
   77 |     int ans = 0;
      |     ^~~
a.cc:77:9: error: 'ans' was not declared in this scope; did you mean 'abs'?
   77 |     int ans = 0;
      |         ^~~
      |         abs
a.cc:50:18: error: declaration does not declare anything [-fpermissive]
   50 | #define int long long;
      |                  ^~~~
a.cc:29:27: note: in expansion of macro 'int'
   29 | #define IFOR(i, a, b) for(int (i)=(a);(i)<=(b);(i)++)
      |                           ^~~
a.cc:78:5: note: in expansion of macro 'IFOR'
   78 |     IFOR(i, 1, n){
      |     ^~~~
a.cc:29:47: error: expected ')' before ';' token
   29 | #define IFOR(i, a, b) for(int (i)=(a);(i)<=(b);(i)++)
      |                          ~                    ^
a.cc:78:5: note: in expansion of macro 'IFOR'
   78 |     IFOR(i, 1, n){
      |     ^~~~