#include using namespace std; using ll = long long; struct A { int v, w; bool operator < (const A& o) const { return w < o.w; } } a[10010]; ll dp[2][10000010]; int main() { cin.tie(nullptr)->sync_with_stdio(false); int n, m; cin >> n >> m; for (int i = 1;i <= n;i++) { cin >> a[i].w >> a[i].v; } sort(a + 1, a + 1 + n); for (int i = 1;i <= n;i++) { int now = i & 1, prev = 1 - now; for (int j = 0;j <= m;j++) { dp[now][j] = max(dp[prev][j], dp[now][j - 1]); // 2 * x + w = j if (j < a[i].w) continue; if ((j + a[i].w) % 2 == 1) continue; int x = (j - a[i].w) / 2; dp[now][j] = max(dp[now][j], dp[prev][x] + a[i].v); } } cout << dp[n & 1][m] << '\n'; return 0; }