Language: C++

/*
    Author:zeke
    
    pass System Test!
    GET AC!!
*/
#include <iostream>
#include <queue>
#include <vector>
#include <iostream>
#include <vector>
#include <string>
#include <cassert>
#include <algorithm>
#include <functional>
#include <cmath>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <map>
#include <iomanip>
#include <utility>
#include <stack>
using ll = long long;
using ld = long double;
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define rep3(var, min, max) for (ll(var) = (min); (var) < (max); ++(var))
#define repi3(var, min, max) for (ll(var) = (max)-1; (var) + 1 > (min); --(var))
#define Mp(a, b) make_pair((a), (b))
#define F first
#define S second
#define Icin(s) \
    ll(s);      \
    cin >> (s);
#define Scin(s) \
    ll(s);      \
    cin >> (s);
template <class T>
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b)
{
    if (b < a)
    {
        a = b;
        return 1;
    }
    return 0;
}
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef vector<V> VV;
typedef vector<P> VP;
ll MOD = 1e9 + 7;
ll INF = 1e18;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    VV dp(5000, V(5000));

    ll n, t;
    cin >> n >> t;]
    VP vec(n);
    rep(i, n)
    {
        ll a, b;
        cin >> a >> b;
        vec[i] = {a, b};
    }
    if(t==1){
        ll Max=0;
        rep(i,n){
            chmax(Max,vec[i].S);
        }
        cout<<Max<<endl;
        return 0;
    }
    // sort(all(vec),)
    // cout<<vec[0].F<<" "<<vec[0].S<<endl;
    VV reg(5000, V(5000));
    //   cout<<n<<endl;
    rep3(i, 0, n + 1)
    {
        // cout<<i<<endl;
        //   cout<<vec[i - 1].S<<endl;
        rep(j, t + 10)
        {
            if (j >= vec[i].F)
            {
                if (dp[i+1][j] < dp[i][j - vec[i].F] + vec[i].S)
                {
                    dp[i + 1][j] = dp[i][j - vec[i].F] + vec[i].S;
                    reg[i + 1][j] = j - vec[i].F;
                }
            }
            if (dp[i + 1][j] < dp[i][j])
            {
                dp[i + 1][j] = dp[i][j];
                reg[i + 1][j] = j;
            }
        }
    }
   // cout << "Selected items are..." << endl;
    int cur_w = t;
    vector<bool> have(n,false);
    for (int i = n-1; i >= 0; --i) {
        // 選んでいた場合
        if (reg[i+1][cur_w] == cur_w - vec[i].F) {
         //   cout << i << " th item (weight = " << vec[i].F << ", value = " << vec[i].S << ")" << endl;
            vec.erase(vec.begin()+i);
        }
        
        // 復元テーブルをたどる
        cur_w = reg[i+1][cur_w];
    }
    
  //  cout<<vec.size()<<endl;
    ll Max=0;
    if(dp[n][t]==dp[n][t-1]){
        rep(i,vec.size()){
            chmax(Max,vec[i].S);
        }
    }
  //  sort(all(result),greater<ll>());
   
    cout << dp[n][t]+Max << endl;
   // cout << reg[n][t] << endl;
}





Compiler output:
a.cc: In function 'int main()':
a.cc:75:19: error: expected primary-expression before ']' token
   75 |     cin >> n >> t;]
      |                   ^
a.cc:81:9: error: 'vec' was not declared in this scope
   81 |         vec[i] = {a, b};
      |         ^~~
a.cc:86:23: error: 'vec' was not declared in this scope
   86 |             chmax(Max,vec[i].S);
      |                       ^~~
a.cc:101:22: error: 'vec' was not declared in this scope
  101 |             if (j >= vec[i].F)
      |                      ^~~
a.cc:121:40: error: 'vec' was not declared in this scope
  121 |         if (reg[i+1][cur_w] == cur_w - vec[i].F) {
      |                                        ^~~
a.cc:133:15: error: 'vec' was not declared in this scope
  133 |         rep(i,vec.size()){
      |               ^~~
a.cc:28:45: note: in definition of macro 'rep'
   28 | #define rep(i, n) for (int i = 0; i < (int)(n); i++)
      |                                             ^