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};
    }
    sort(all(vec))
    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;
    ll res=0;
    
    for(ll foo=t;foo<=t;foo++){
        ll cur_w=foo;
        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;
                have[i]=true;
            }
            
            // 復元テーブルをたどる
            cur_w = reg[i+1][cur_w];
        }
        ll Max=0;
        if(dp[n][t]==dp[n][t-1]){
            rep(i,vec.size()){
                if(have[i])continue;
                chmax(Max,vec[i].S);
            }
        }
        chmax(res,dp[n][foo]+Max);
    }
  //  cout<<vec.size()<<endl;
    
  //  sort(all(result),greater<ll>());
   
    cout << res<< endl;
   // cout << reg[n][t] << endl;
}





Compiler output:
a.cc: In function 'int main()':
a.cc:83:19: error: expected ';' before 'if'
   83 |     sort(all(vec))
      |                   ^
      |                   ;
   84 |     if(t==1){
      |     ~~