#include #include #include #include #include using namespace std; int main() { int n, k; cin >> n >> k; int dp[2][10001] = {}; vector> vs; for (int i = 0; i < n; i++) { int p, d; cin >> p >> d; vs.push_back({p, d}); } sort(vs.rbegin(), vs.rend()); for (auto v : vs) { int p, d; tie(p, d) = v; for (int e = k; e > 0; e--) { if (dp[0][e] != 0) { dp[1][e + p] = max(dp[1][e + p], dp[0][e] + d); } if (dp[1][e] != 0) { dp[0][e] = max(dp[0][e], dp[1][e] + d); } } dp[1][p] = max(dp[1][p], d); } int ans = 0; for (int i = 0; i < 2; i++) { for (int j = 0; j <= k; j++) { ans = max(ans, dp[i][j]); } } cout << ans << endl; return 0; }