/** * author: zjs * created: 25.06.2026 11:19:42 **/ #include using namespace std; const int maxm = 1e3 + 5; long long f[10][maxm]; struct Card { int c, d; }; bool cmp(Card a, Card b) { return a.c > b.c; } int main() { ios::sync_with_stdio(0); cin.tie(0); long long sum = 0; vector a; int N, M; cin >> N >> M; for (int i = 0; i < N; i++) { int c, d; cin >> c >> d; if (c == 0) sum += d; else a.push_back({c, d}); } sort(a.begin(), a.end(), cmp); for (auto [c, d] : a) { for (int j = 9; j >= 1; j--) { int cost = c << (j - 1); for (int k = cost; k <= M; k++) f[j][k] = max(f[j][k], f[j - 1][k - cost] + d); } } long long ans = 0; for (int j = 0; j <= 9; j++) ans = max(ans, f[j][M]); cout << ans + sum << '\n'; }