#include #include #include #include #include #include #include #include #include #include #include #include using namespace std; using namespace atcoder; typedef long long ll; #define rep(i,n) for (int i = 0; i < int(n);i++) int main(){ int n; cin >> n; int I = 0; cin >> I; vector s(n); vector a(n); rep(i,n){ cin >> s[i] >> a[i]; } vector> dp(2,vector(1010,-1)); int now = 0,next = 1; dp[0][0] = 0; for (int i = 0; i < n;i++){ for (int j = 0; j <= I;j++){ if (s[i] + j <= I){ dp[next][j+s[i]] = max(dp[next][j+s[i]],dp[now][j]+a[i]); } dp[next][j] = max(dp[next][j],dp[now][j]); } swap(now,next); } int ans = 0; for (int i = 0; i <= I;i++){ ans = max(ans,dp[now][i]); } cout << ans << endl; return 0; }