/** * code generated by JHelper * More info: https://github.com/AlexeyDmitriev/JHelper * @author aajisaka */ #include using namespace std; void debug_out() { cerr << endl; } template void debug_out(Head H, Tail... T) { cerr << " " << to_string(H); debug_out(T...); } #ifdef LOCAL #define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__) #else #define debug(...) 42 #endif #define SPEED ios_base::sync_with_stdio(false);cin.tie(nullptr) #define rep(i,n) for(int i=0; i<(int)(n); i++) #define all(v) v.begin(), v.end() template inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; } template inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; } using ll = long long; using P = pair; constexpr double PI = 3.14159265358979323846; mt19937_64 engine(chrono::steady_clock::now().time_since_epoch().count()); class Insyuprogrammingcontest { public: int n; vector d; bool calc(int k, vector>& dp, vector>& check) { if (k==0) return true; check[0][0] = true; for(int i=0; i<=k; i++) { for(int j=0; i+j<=k; j++) { if (i==0 && j==0) continue; int p = i+j; bool flag = false; if (i>0 && check[i-1][j]) flag = true; if (j>0 && check[i][j-1]) flag = true; if (flag && dp[i][j] >= d[n-k+p-1]) { check[i][j] = true; debug(i, j, k); if (i+j==k) return true; } else { check[i][j] = false; } } } return false; } void solve(istream& cin, ostream& cout) { SPEED; cin >> n; vector a(n+1), b(n+1); d.resize(n); rep(i, n+1) { cin >> a[i]; } rep(i, n+1) { cin >> b[i]; } rep(i, n) { cin >> d[i]; } sort(d.rbegin(), d.rend()); vector> dp(n+1, vector(n+1)); vector> check(n+1, vector(n+1)); rep(i, n+1) { rep(j, n+1) { dp[i][j] = a[i] + b[j]; } } int mi = 0; int ma = n+1; while(mi+1 < ma) { int k = (mi+ma)/2; if (calc(k, dp, check)) { mi = k; } else { ma = k; } } cout << mi << endl; } }; signed main() { Insyuprogrammingcontest solver; std::istream& in(std::cin); std::ostream& out(std::cout); solver.solve(in, out); return 0; }