#include #define rep(i,n) for(int i = 0; i < (n); i++) using namespace std; using ll = long long; using ld = long double; int main(){ cin.tie(0); ios::sync_with_stdio(0); int N,M; cin >> N >> M; vector> J(N); for(auto &[v, w] : J) cin >> v >> w; sort(J.begin(), J.end(), [&](pair L, pair R) { auto [vL, wL] = L; auto [vR, wR] = R; if(vL != vR) return vL > vR; return wL < wR; }); vector dp(M + 1, 0); ll ans = 0; for(auto [v, w] : J) { vector nt = dp; for(int k = 0; k <= M; k++) { if(k + w <= M) nt[k + w] = max(nt[k + w], dp[k] + v); } swap(dp, nt); ans = max(ans, *max_element(dp.begin(), dp.end()) * v); } cout << ans << endl; }