#include using namespace std; int main() { int N, I; scanf("%d %d", &N, &I); vector s(N), a(N); for (int i = 0; i < N; i++) scanf("%d %d", &s[i], &a[i]); vector > dp(N + 1, vector (I + 1)); for (int i = 0; i <= N; i++) { for (int j = 0; j <= I; j++) { if (i == 0 || j == 0) dp[i][j] = 0; else if (s[i - 1] <= j) dp[i][j] = max(a[i - 1] + dp[i - 1][j - s[i - 1]], dp[i - 1][j]); else dp[i][j] = dp[i - 1][j]; } } cout << dp[N][I]; return 0; }