#include using namespace std; #define rep(i, n) for (int i = 0; i < (n); i++) #define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--) typedef long long ll; typedef pair P; template auto Sum(T a, U b) -> decltype(a + b) { return a + b; } template inline bool amax(T &a, U b) { if (b > a) { a = b; return true; } return false; } template inline bool amin(T &a, U b) { if (b < a) { a = b; return true; } return false; } int main() { int N, M; cin >> N >> M; vector

items(N); rep(i, N) cin >> items[i].first >> items[i].second; sort(items.begin(), items.end(), [](P x, P y) { return x.first > y.first; }); ll ans = 0; vector dp(M + 1); for (auto &p : items) { int v = p.first, w = p.second; for (int j = M; j >= w; --j) { amax(dp[j], dp[j - w] + v); } amax(ans, dp[M] * v); } cout << ans << endl; }