#include #include using namespace std; using ll = long long; using mint = atcoder::modint998244353; int main(){ ios::sync_with_stdio(false); cin.tie(0); int n, W; cin >> n >> W; W += 10000; vector> a(n); for(auto &&[v, w] : a){ cin >> v >> w; swap(v, w); } sort(a.begin(), a.end()); const int r = max(10000, W); vector dp1(r + 1); vector dp2(r + 1, -(1 << 30)); dp1[10000] = 1; dp2[10000] = 0; for(auto &&[w, v] : a){ if(w >= 0){ for(int j = r - w; j >= 0; j--){ const int v2 = dp2[j] + v; const int to = j + w; if(dp2[to] == v2){ dp1[to] += dp1[j]; }else if(dp2[to] < v2){ dp2[to] = v2; dp1[to] = dp1[j]; } } }else{ for(int j = -w; j <= r; j++){ const int v2 = dp2[j] + v; const int to = j + w; if(dp2[to] == v2){ dp1[to] += dp1[j]; }else if(dp2[to] < v2){ dp2[to] = v2; dp1[to] = dp1[j]; } } } } int mx = -(1 << 30); for(int i = 0; i <= W; i++){ if(dp2[i] > mx) mx = dp2[i]; } mint ans; for(int i = 0; i <= W; i++) if(dp2[i] == mx) ans += dp1[i]; cout << mx << ' ' << ans.val() << '\n'; }