Language: C++

#include "bits/stdc++.h"
#define rep(i,n) for(ll i = 0; i < n; i++)
typedef long long ll;
using namespace std;
#define llMAX numeric_limits<long long>::max()
#define intMAX numeric_limits<int>::max()
#define d_5 100000
#define d9_7 1000000007
#define vll vector<vector<long long>>
#define vl vector<long long>
#define vi vector<int>
#define vii vector<vector<int>>
#define pb push_back
#define pf push_front
#define ld long double
#define ll long long
struct meal{
  ll a;
  ll b;
};
bool cmp1(const meal &a, const meal &b)//ソート用
{
    if(a.b!=b.b){
      return a.b<b.b;
      }else{
        return a.a<b.a;
      }
}
bool cmp2(const meal &a, const meal &b)//ソート用
{
    if(a.a!=b.a){
      return a.a<b.a;
      }else{
        return a.b>b.b;
      }
}
int main(void){
  ll n,t;
  cin>>n>>t;
  t++;
  vector<meal> m(n);
  rep(i,n){
    cin>>m[i].a>>m[i].b;
  }
  
  vll dp=vll(n+1,vl(t,0));
  /*rep(i,n){
    rep(j,t){
      if(j+m[i].a<t){
        dp[i+1][j+m[i].a]=dp[i][j]+m[i].b;
      }
      dp[i+1][j]=max(dp[i][j],dp[i+1][j]);
    }
  }
  /*rep(i,n){
    rep(j,t){
      cout<<dp[i][j]<<" ";
    }
    cout<<endl;
  }*/
  ll amax=0;
  rep(i,t){
    amax=max(amax,dp[n][i]);
 
  }
  ll ans1=0;
  dp=vll(n+1,vl(t,0));
  sort(m.begin(),m.end(),cmp1);
  t-=1;
  ll tmpans=m[n-1].b;
  rep(i,n-1){
    rep(j,t){
      if(j+m[i].a<t){
        dp[i+1][j+m[i].a]=dp[i][j]+m[i].b;
      }
      dp[i+1][j]=max(dp[i][j],dp[i+1][j]);
    }
  }
  /*rep(i,n){
    rep(j,t){
      cout<<dp[i][j]<<" ";
    }
    cout<<endl;
  }*/
  amax=0;
  rep(i,t){
    amax=max(amax,dp[n-1][i]);
 
  }
  ans1=max(amax+tmpans,ans1);
  /*dp=vll(n+1,vl(t,0));
  sort(m.begin(),m.end(),cmp2);
  tmpans=m[n-1].b;
  rep(i,n-1){
    rep(j,t){
      if(j+m[i].a<t){
        dp[i+1][j+m[i].a]=dp[i][j]+m[i].b;
      }
      dp[i+1][j]=max(dp[i][j],dp[i+1][j]);
    }
  }
  /*rep(i,n){
    rep(j,t){
      cout<<dp[i][j]<<" ";
    }
    cout<<endl;
  }*/
  /*amax=0;
  rep(i,t){
    amax=max(amax,dp[n-1][i]);
 
  }*/
  cout<<max(amax+tmpans,ans1)<<endl;
  return 0;
}#include "bits/stdc++.h"
#define rep(i,n) for(ll i = 0; i < n; i++)
typedef long long ll;
using namespace std;
#define llMAX numeric_limits<long long>::max()
#define intMAX numeric_limits<int>::max()
#define d_5 100000
#define d9_7 1000000007
#define vll vector<vector<long long>>
#define vl vector<long long>
#define vi vector<int>
#define vii vector<vector<int>>
#define pb push_back
#define pf push_front
#define ld long double
#define ll long long
struct meal{
  ll a;
  ll b;
};
bool cmp1(const meal &a, const meal &b)//ソート用
{
    if(a.b!=b.b){
      return a.b<b.b;
      }else{
        return a.a<b.a;
      }
}
bool cmp2(const meal &a, const meal &b)//ソート用
{
    if(a.a!=b.a){
      return a.a<b.a;
      }else{
        return a.b>b.b;
      }
}
int main(void){
  ll n,t;
  cin>>n>>t;
  t++;
  vector<meal> m(n);
  rep(i,n){
    cin>>m[i].a>>m[i].b;
  }
  
  vll dp=vll(n+1,vl(t,0));
  /*rep(i,n){
    rep(j,t){
      if(j+m[i].a<t){
        dp[i+1][j+m[i].a]=dp[i][j]+m[i].b;
      }
      dp[i+1][j]=max(dp[i][j],dp[i+1][j]);
    }
  }
  /*rep(i,n){
    rep(j,t){
      cout<<dp[i][j]<<" ";
    }
    cout<<endl;
  }*/
  ll amax=0;
  rep(i,t){
    amax=max(amax,dp[n][i]);
 
  }
  ll ans1=0;
  dp=vll(n+1,vl(t,0));
  sort(m.begin(),m.end(),cmp1);
  t-=1;
  ll tmpans=m[n-1].b;
  rep(i,n-1){
    rep(j,t){
      if(j+m[i].a<t){
        dp[i+1][j+m[i].a]=dp[i][j]+m[i].b;
      }
      dp[i+1][j]=max(dp[i][j],dp[i+1][j]);
    }
  }
  /*rep(i,n){
    rep(j,t){
      cout<<dp[i][j]<<" ";
    }
    cout<<endl;
  }*/
  amax=0;
  rep(i,t){
    amax=max(amax,dp[n-1][i]);
 
  }
  ans1=max(amax+tmpans,ans1);
  /*dp=vll(n+1,vl(t,0));
  sort(m.begin(),m.end(),cmp2);
  tmpans=m[n-1].b;
  rep(i,n-1){
    rep(j,t){
      if(j+m[i].a<t){
        dp[i+1][j+m[i].a]=dp[i][j]+m[i].b;
      }
      dp[i+1][j]=max(dp[i][j],dp[i+1][j]);
    }
  }
  /*rep(i,n){
    rep(j,t){
      cout<<dp[i][j]<<" ";
    }
    cout<<endl;
  }*/
  /*amax=0;
  rep(i,t){
    amax=max(amax,dp[n-1][i]);
 
  }*/
  cout<<max(amax+tmpans,ans1)<<endl;
  return 0;
}

Compiler output:
a.cc:115:2: error: stray '#' in program
  115 | }#include "bits/stdc++.h"
      |  ^
a.cc:115:3: error: 'include' does not name a type
  115 | }#include "bits/stdc++.h"
      |   ^~~~~~~
a.cc:131:8: error: redefinition of 'struct meal'
  131 | struct meal{
      |        ^~~~
a.cc:17:8: note: previous definition of 'struct meal'
   17 | struct meal{
      |        ^~~~
a.cc:135:6: error: redefinition of 'bool cmp1(const meal&, const meal&)'
  135 | bool cmp1(const meal &a, const meal &b)//ソート用
      |      ^~~~
a.cc:21:6: note: 'bool cmp1(const meal&, const meal&)' previously defined here
   21 | bool cmp1(const meal &a, const meal &b)//ソート用
      |      ^~~~
a.cc:143:6: error: redefinition of 'bool cmp2(const meal&, const meal&)'
  143 | bool cmp2(const meal &a, const meal &b)//ソート用
      |      ^~~~
a.cc:29:6: note: 'bool cmp2(const meal&, const meal&)' previously defined here
   29 | bool cmp2(const meal &a, const meal &b)//ソート用
      |      ^~~~
a.cc:151:5: error: redefinition of 'int main()'
  151 | int main(void){
      |     ^~~~
a.cc:37:5: note: 'int main()' previously defined here
   37 | int main(void){
      |     ^~~~