#include #include #include using namespace atcoder; using mint = modint998244353; using namespace std; #define rep(i,n) for (int i = 0; i < (n); ++i) #define Inf32 1000000001 #define Inf64 1000000000000000001 using P = pair; P op(P a,P b){ if(a.first>b.first)return a; if(a.first>N>>W; vector

dp(20001,e()); int c = 10000; dp[c] = make_pair(0,1); vector> items(N); rep(i,N){ int x,y; cin>>x>>y; items[i] = make_pair(y,x); } sort(items.begin(),items.end()); rep(i,N){ int v,w; v = items[i].second,w = items[i].first; vector

ndp(20001,e()); rep(j,20001){ P val = dp[j]; if(val.first==-Inf32)continue; ndp[j] = op(ndp[j],val); int nj = j + w; if(nj<0 || nj>=ndp.size())continue; val.first += v; ndp[nj] = op(ndp[nj],val); } swap(dp,ndp); } W += c; P ans = e(); rep(i,W+1){ ans = op(ans,dp[i]); } cout<