#include using namespace std; #define ALL(x) begin(x),end(x) #define rep(i,n) for(int i=0;i<(n);i++) #define debug(v) cout<<#v<<":";for(auto x:v){cout<bool chmax(T &a,const T &b){if(abool chmin(T &a,const T &b){if(b ostream &operator<<(ostream &os,const vector&v){ for(int i=0;i<(int)v.size();i++) os< istream &operator>>(istream &is,vector&v){ for(T &x:v)is>>x; return is; } signed main(){ int n,k;cin>>n>>k; vector p(n),d(n); rep(i,n) cin>>p[i]>>d[i]; vector ord(n); iota(ALL(ord),0); sort(ALL(ord),[&](int l,int r){return p[l]>p[r];}); vector>> dp(n+1,vector>(k+1,vector(2,-INF))); dp[0][0][0]=0; rep(i,n){ rep(j,k+1){ chmax(dp[i+1][j][0],dp[i][j][0]); chmax(dp[i+1][j][1],dp[i][j][1]); int cost=p[ord[i]],val=d[ord[i]]; if(j+cost<=k){ chmax(dp[i+1][j+cost][1],dp[i][j][0]+val); chmax(dp[i+1][j+cost][1],dp[i][j][1]+val); } chmax(dp[i+1][j][0],dp[i][j][1]+val); } } int res=0; rep(i,n+1)rep(j,k+1)rep(l,2) chmax(res,dp[i][j][l]); cout<