#include #include using namespace std; using ll = long long; using ld = long double; using ull = long long; #define endl "\n" #define REP3(i, m, n) for (int i = (m); (i) < int(n); ++ (i)) #define rep(i,a,b) for(int i=(int)(a);i<(int)(b);i++) #define ALL(x) begin(x), end(x) #define all(s) (s).begin(),(s).end() //#define rep2(i, m, n) for (int i = (m); i < (n); ++i) //#define rep(i, n) rep2(i, 0, n) #define drep2(i, m, n) for (int i = (m)-1; i >= (n); --i) #define drep(i, n) drep2(i, n, 0) #define rever(vec) reverse(vec.begin(), vec.end()) #define sor(vec) sort(vec.begin(), vec.end()) #define fi first #define se second #define pb push_back #define P pair #define REP(i, n) for (int i = 0; i < (n); ++i) #define in scanner.read_int() //const ll mod = 998244353; const ll mod = 1000000007; const ll inf = 4500000000000000000ll; static const long double pi = 3.141592653589793; templatevoid vcin(vector &n){for(int i=0;i>n[i];} templatevoid vcin(vector &n,vector &m){for(int i=0;i>n[i]>>m[i];} templatevoid vcout(vector &n){for(int i=0;ivoid vcin(vector> &n){for(int i=0;i>n[i][j];}}} templatevoid vcout(vector> &n){for(int i=0;ibool chmax(T &a, const T &b) { if (a>a>>b; vector x(a-1); vector y(a-1); vector t(a); vcin(t); sor(t); for(int i=0;i> dp(7000,vector(7000,-inf)); rever(x); rever(y); dp[0][0]=0; for(int i=0;i<=a+5;i++){ if(1){ for(int j=0;j<=6999;j++) chmax(dp[i+1][j],dp[i][j]); } if(i=0) chmax(dp[i+2][j],dp[i][j-y[i]]+x[i]); chmax(dp[i+2][j],dp[i][j]); } } for(int j=1;j<=6999;j++) chmax(dp[i][j],dp[i][j-1]); } cout<