#include using namespace std; using ll = long long; using pll = pair; #define all(a) (a).begin(), (a).end() #define pb push_back #define fi first #define se second mt19937_64 rng(chrono::system_clock::now().time_since_epoch().count()); const ll MOD1000000007 = 1000000007; const ll MOD998244353 = 998244353; const ll MOD[3] = {999727999, 1070777777, 1000000007}; const ll LINF = 1LL << 60LL; const int IINF = (1 << 30) - 1; void solve(){ int n, m; cin >> n >> m; vector> C; ll ans = 0LL; for(int i=0; i> c >> d; if(c == 0) ans += d; else C.push_back({c, d}); } int MX = 25; vector two(MX+1, 1); for(int i=1; i<=MX; i++) two[i] = two[i-1]*2; n = (int)C.size(); vector cnt(n, 0); for(int i=0; i>()); vector> dp(m+1, vector(MX+1, -1)); dp[0][0] = 0; for(int i=0; i=0; j--){ for(int k=cnt[i]; k>=0; k--){ if(j - c*two[k] >= 0) dp[j][k] = max(dp[j][k], dp[j - c*two[k]][k-1] + d); } } } ll sa = 0LL; for(int i=0; i<=m; i++) { for(int j=0; j<=MX; j++){ if(dp[i][j] != -1) sa = max(sa, dp[i][j]); } } cout << sa + ans << '\n'; } int main(){ cin.tie(nullptr); ios::sync_with_stdio(false); int T=1; //cin >> T; while(T--) solve(); }