#if !__INCLUDE_LEVEL__ #include __FILE__ struct Solver { void solve() { int n,m;cin>>n>>m; V s(n),a(n); rep(i,n)cin>>s[i]>>a[i]; V> dp(n+1,V(m+1,-INFL)); dp[0][0]=0; rep(i,n){ rep(j,m+1){ chmax(dp[i+1][j],dp[i][j]); if(j+s[i]<=m)chmax(dp[i+1][j+s[i]],dp[i][j]+a[i]); } } ll ans=0; rep(i,m+1)chmax(ans,dp[n][i]); cout< #include using namespace atcoder; // #include // #include // using namespace __gnu_pbds; using namespace std; #define int ll using ll=long long; using ld = long double; using uint = unsigned; using ull = unsigned long long; using P=pair; using TP=tuple; template using V = vector; template using max_heap = priority_queue; template using min_heap = priority_queue, greater<>>; #define FOR1(a) for (ll _ = 0; _ < ll(a); ++_) #define FOR2(i, a) for (ll i = 0; i < ll(a); ++i) #define FOR3(i, a, b) for (ll i = a; i < ll(b); ++i) #define FOR4(i, a, b, c) for (ll i = a; i < ll(b); i += (c)) #define FOR1_R(a) for (ll i = (a)-1; i >= ll(0); --i) #define FOR2_R(i, a) for (ll i = (a)-1; i >= ll(0); --i) #define FOR3_R(i, a, b) for (ll i = (b)-1; i >= ll(a); --i) #define FOR4_R(i, a, b, c) for (ll i = (b)-1; i >= ll(a); i -= (c)) #define overload4(a, b, c, d, e, ...) e #define rep(...) overload4(__VA_ARGS__, FOR4, FOR3, FOR2, FOR1)(__VA_ARGS__) #define rrep(...) overload4(__VA_ARGS__, FOR4_R, FOR3_R, FOR2_R, FOR1_R)(__VA_ARGS__) #define fore(i,a) for(auto &i:a) #define all(x) x.begin(),x.end() #define sz(x) ((int)(x).size()) #define bp(x) (__builtin_popcountll((long long)(x))) #define elif else if #define mpa make_pair #define bit(n) (1LL<<(n)) #define LB(c, x) distance((c).begin(), lower_bound(all(c), (x))) #define UB(c, x) distance((c).begin(), upper_bound(all(c), (x))) #define UNIQUE(x) sort(all(x)), x.erase(unique(all(x)), x.end()) templatebool chmax(T &a, const T &b) { if (abool chmin(T &a, const T &b) { if (bistream& operator>>(istream&i,vector&v){rep(j,sz(v))i>>v[j];return i;} templatestring join(const T&v,const string& d=""){stringstream s;rep(i,sz(v))(i?s<ostream& operator<<(ostream&o,const vector&v){if(sz(v))o<istream& operator>>(istream&i,pair&v){return i>>v.first>>v.second;} templateostream& operator<<(ostream&o,const pair&v){return o<bool mins(T1& x,const T2&y){if(x>y){x=y;return true;}else return false;} templatebool maxs(T1& x,const T2&y){if(xTx dup(Tx x, Ty y){return (x+y-1)/y;} templatell suma(const vector&a){ll res(0);for(auto&&x:a)res+=x;return res;} templatell suma(const V>&a){ll res(0);for(auto&&x:a)res+=suma(x);return res;} templatevoid uni(T& a){sort(rng(a));a.erase(unique(rng(a)),a.end());} templatevoid prepend(vector&a,const T&x){a.insert(a.begin(),x);} const int INF = 1001001001; const ll INFL = 3e18; const int MAX = 2e6+5; #endif