#include #include #include using namespace std; int main() { int N, K; cin >> N >> K; vector dp(K + 1); for (int i = 0; i < N; ++i) { int P, D; cin >> P >> D; for (int j = K; j >= P; --j) { dp[j] = max(dp[j], dp[j - P] + D); } } cout << dp[N] << endl; return 0; }