#include using namespace std; using ll = long long; using pll = pair; const ll NEG = -(1LL << 60); int main() { ios::sync_with_stdio(false); cin.tie(nullptr); ll N, M; cin >> N >> M; vector VW(N); for (auto &[v, w] : VW) cin >> v >> w; sort(VW.rbegin(), VW.rend()); // 美しさ降順 vector dp(M + 1, NEG); dp[0] = 0; ll ans = 0; ll best = 0; // 現時点での美しさ総和の最大値 for (auto [v, w] : VW) { for (ll j = M - w; j >= 0; --j) { if (dp[j] == NEG) continue; dp[j + w] = max(dp[j + w], dp[j] + v); best = max(best, dp[j + w]); } ans = max(ans, v * best); } cout << ans << '\n'; return 0; }