#include using namespace std; using Int = long long; template inline void chmin(T1 &a,T2 b){if(a>b) a=b;} template inline void chmax(T1 &a,T2 b){if(a>n; vector v(n),t(n); for(Int i=0;i>v[i]>>t[i]; using P = pair; vector

vp; for(Int i=0;i dp(MAX,0); dp[0]=1; for(Int i=0;i=0;j--){ if(!dp[j]||j>=t[i]) continue; chmax(ans,j+v[i]); if(j+v[i]