#include using namespace std; int main() { int n, m; cin >> n >> m; int dp[1005]{0}; for (int i = 0; i < n; i++) { int s, a; cin >> s >> a; int d[1005]; for (int j = 0; j <= m; j++) { d[j] = dp[j]; } for (int j = s; j <= m; j++) { d[j] = max(d[j], dp[j - s] + a); } swap(dp, d); } cout << dp[m] << endl; }