#include #define fst(t) std::get<0>(t) #define snd(t) std::get<1>(t) using P = std::tuple; int main(){ std::cin.tie(nullptr); std::ios::sync_with_stdio(false); int N, W; std::cin >> N >> W; std::vector v(N), w(N); for(int i=0;i> v[i] >> w[i]; } constexpr int MOD = 998244353; std::vector dp( N + 1, std::vector

( 30001, std::make_tuple(std::numeric_limits::min(), 0) ) ); dp[0][10000] = std::make_tuple(0, 1); auto merge = [](const P p, const P q){ if(fst(p) > fst(q)){ return p; }else if(fst(p) < fst(q)){ return q; } return std::make_tuple(fst(p), (snd(p) + snd(q)) % MOD); }; for(int i=0;i::min()){ continue; } dp[i + 1][j] = merge(dp[i + 1][j], dp[i][j]); int nj = j + w[i]; if(nj < dp[0].size()){ dp[i + 1][nj] = merge(dp[i + 1][nj], std::make_tuple(max_v + v[i], n)); } } } P res = std::make_tuple(std::numeric_limits::min(), 0); for(int j=0;j<=W+10000;j++){ res = merge(res, dp[N][j]); } std::cout << fst(res) << " " << snd(res) << std::endl; }