#include #include #include #include #include #include #include #include #include #include #include using namespace std; typedef long long ll; struct Jewelry { ll v; ll w; Jewelry(ll v = -1, ll w = -1) { this->v = v; this->w = w; } bool operator<(const Jewelry &n) const { return v > n.v; } }; ll dp[5010][5010]; int main() { int N, M; cin >> N >> M; vector gems; for (int i = 0; i < N; ++i) { ll v, w; cin >> v >> w; gems.push_back(Jewelry(v, w)); } sort(gems.begin(), gems.end()); memset(dp, 0, sizeof(dp)); ll ans = 0; for (int i = 0; i < N; ++i) { Jewelry j = gems[i]; for (int w = M; w >= 0; --w) { int nw = w + j.w; ll nv = dp[i][w] + j.v; dp[i + 1][w] = dp[i][w]; if (M < nw) continue; if (dp[i + 1][nw] < nv) { dp[i + 1][nw] = nv; ans = max(ans, nv * j.v); } } } cout << ans << endl; return 0; }