#include //#include //#include #define int long long #define ld long double #define get(T,args...) T args; read(args); #define init(a,T,n,s) vector a((n)+1,s); cin>>a; #define putn(args...) { put(args); cout<<"\n"; } #define pute(args...) { put(args); cout<(b); i--) #define logarr(arr,f,l) { auto start=arr.begin(), end=arr.begin(); advance(start,(f)); advance(end,(l)); for(auto it=start; it!=end; it++) cout<<*it<<" "; cout<<"\n"; } #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(), x.rend() #define sort_by(span,p) sort(span, [&](const auto &l, const auto &r) { return p; }) #define f(u, args...) [&](auto &&u) { return args; } #define g(u, v, args...) [&](auto &&u, auto &&v) { return args; } #define uniq(x) x.erase(unique(all(x)),x.end()); #define sz(x) (int)(x).size() #define mid(l,r) std::midpoint((l),(r)) #define zov(v,z,c) ((c) ? (v) : (z)) #define pii pair #define pb emplace_back #define pf push_front #define fr first #define sc second #define sumv(v,b,e) accumulate((v).begin()+b,(v).begin()+e,0LL) #define minv(v,b,e) min_element((v).begin()+b,(v).begin()+e) #define maxv(v,b,e) max_element((v).begin()+b,(v).begin()+e) #define precise(n) cout< #define set(args...) std::set > #define pqueue(args...) std::priority_queue,Comp > //#define oset(args...) tree, rb_tree_tag, tree_order_statistics_node_update> const int N = 100001, M = 998244353, mod = 1000000007, MX = INT64_MAX, MN = INT64_MIN, oo = 1e18; #ifdef DEBUG #include "./Debug/debug.hpp" #else #define debug(args...) 0; #pragma GCC optimize("O3,unroll-loops") #pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt") #endif //using namespace __gnu_pbds; using namespace std; vec(string) tokenizer(string str,char ch) {std::istringstream var((str)); vec(string) v; string t; while(getline((var), t, (ch))) {v.pb(t);} return v;} template struct Comp { bool operator()(const T& l, const T& r) const { return l < r; } }; template inline istream& operator >> (istream& in, pair& a) { in>>a.first>>a.second; return in; } template inline ostream& operator << (ostream& out, pair a) { out< istream& operator >> (istream& in, vector& v) { rep(i,1,sz(v)) cin>>v[i]; return in; } template inline bool amax(T &a,T1 b){ if(b>a) { a=b; return true; } return false; } template inline bool amin(T &a,T1 b){ if(b>args), ...); } void put(auto&&... args) { ((cout< items(n); for(auto& [v,w]:items) read(v,w); sort(rall(items)); int ans = 0; vector dp(m+1); //dp[i] denotes max value that can be obtained by a knapsack of weight i for(auto& [v,w]:items) { repr(i,m-w,-1) { amax(dp[i+w],dp[i] + v); amax(ans,(dp[i] + v)*v); } } putn(ans) } signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); //file_i_o(); int t=1; rep(i,1,t+1) { //cout<<"Case #"<