#include #include using namespace std; using namespace atcoder; #define rep(i,n) for(int i=0;i<(n);i++) typedef long long ll; //using mint = modint; using mint = modint998244353; using P = pair; const ll INF=1LL<<60, dx[]={0,1,0,-1},dy[]={1,0,-1,0}; bool chmin(ll& a,ll b){if(a>b){a=b; return 1;} return 0;} bool chmax(ll& a,ll b){if(a> n >> maxi; vector s(n),a(n); rep(i,n) cin >> s[i] >> a[i]; vector> dp(n+1,vector (maxi+1,-INF)); dp[0][0]=0; for(int i=1;i<=n;i++){ rep(j,maxi+1){ if(j-s[i-1]>=0) dp[i][j]=max(dp[i-1][j-s[i-1]]+a[i-1],dp[i-1][j]); else dp[i][j]=dp[i-1][j]; } } /* rep(i,n+1){ rep(j,maxi+1) { cout << i << " " << j << " " << dp[i][j] << endl; } } */ ll ans = 0; rep(i,maxi+1) chmax(ans,dp[n][i]); cout << ans << endl; return 0; }