#pragma GCC optimize("O3") #include #define debug(...) ((void)0) #include using mint = atcoder::modint998244353; namespace atcoder { template * = nullptr> std::ostream& operator<<(std::ostream& os, const static_modint& x) { return os << x.val(); } } // namespace atcoder using namespace std; using ll = long long; using ld = long double; void solve(int) { int N, W; cin >> N >> W; unordered_map> dp; dp[0] = {0, 1}; for (int i = 0; i < N; i++) { int v, w; cin >> v >> w; auto next_dp = dp; for (auto [weight, value] : dp) { if (!next_dp.contains(weight + w) || next_dp[weight + w].first < value.first + v) { next_dp[weight + w] = {value.first + v, value.second}; } else if (next_dp[weight + w].first == value.first + v) { next_dp[weight + w].second += value.second; } } swap(dp, next_dp); debug(dp); } int ans = numeric_limits::min(); for (auto&& [weight, value] : dp) { if (weight <= W) { ans = max(ans, value.first); } } int cnt = 0; for (auto&& [weight, value] : dp) { if (weight <= W && value.first == ans) { cnt += value.second.val(); } } cout << ans << ' ' << cnt << endl; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); solve(0); }