#include <bits/stdc++.h>
#define fi first
#define se second
#define all(v) v.begin() , v.end()
#define sz(v) int(v.size())
#define unq(v) sort(all(v)); v.resize(unique(all(v)) - v.begin());
using namespace std;
typedef long long ll;
typedef pair<int , int> ii;
typedef pair<long long , int> lli;
const int maxN = 3007;
const ll inf = ll(1e18)+7;
int n , t[maxN] , f[maxN];
ll dp[maxN][maxN];
void solve(){
cin >> n;
for (int i = 1 ; i <= n ; i++) cin >> t[i];
for (int i = 1 ; i <= n ; i++) cin >> f[i];
for (int i = 0 ; i <= n ; i++){
for (int j = 0 ; j <= n ; j++) dp[i][j] = inf;
}
dp[0][0] = 0;
for (int i = 1 ; i <= n ; i++){
for (int j = 0 ; j <= n ; j++) dp[i][j] = dp[i - 1][j];
for (int j = 1 ; j <= n ; j++){
if (dp[i - 1][j - 1] <= t[i]){
dp[i][j] = min(dp[i][j] , dp[i - 1][j - 1] + f[i]);
}
}
}
for (int i = n ; i >= 0 ; i--){
if (dp[n][i] != inf){
cout << i << "\n";
return;
}
}
}
#define name "A"
int main(){
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
if (fopen(name".INP" , "r")){
freopen(name".INP" , "r" , stdin);
freopen(name".OUT" , "w" , stdout);
}
int t = 1; //cin >> t;
while (t--) solve();
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CiNkZWZpbmUgZmkgZmlyc3QKI2RlZmluZSBzZSBzZWNvbmQKI2RlZmluZSBhbGwodikgdi5iZWdpbigpICwgdi5lbmQoKQojZGVmaW5lIHN6KHYpIGludCh2LnNpemUoKSkKI2RlZmluZSB1bnEodikgc29ydChhbGwodikpOyB2LnJlc2l6ZSh1bmlxdWUoYWxsKHYpKSAtIHYuYmVnaW4oKSk7CnVzaW5nIG5hbWVzcGFjZSBzdGQ7Cgp0eXBlZGVmIGxvbmcgbG9uZyBsbDsKdHlwZWRlZiBwYWlyPGludCAsIGludD4gaWk7CnR5cGVkZWYgcGFpcjxsb25nIGxvbmcgLCBpbnQ+IGxsaTsKCmNvbnN0IGludCBtYXhOID0gMzAwNzsKY29uc3QgbGwgaW5mID0gbGwoMWUxOCkrNzsKCmludCBuICwgdFttYXhOXSAsIGZbbWF4Tl07CmxsIGRwW21heE5dW21heE5dOwoKdm9pZCBzb2x2ZSgpewogICAgY2luID4+IG47CiAgICBmb3IgKGludCBpID0gMSA7IGkgPD0gbiA7IGkrKykgY2luID4+IHRbaV07CiAgICBmb3IgKGludCBpID0gMSA7IGkgPD0gbiA7IGkrKykgY2luID4+IGZbaV07CiAgICBmb3IgKGludCBpID0gMCA7IGkgPD0gbiA7IGkrKyl7CiAgICAgICAgZm9yIChpbnQgaiA9IDAgOyBqIDw9IG4gOyBqKyspIGRwW2ldW2pdID0gaW5mOwogICAgfQogICAgZHBbMF1bMF0gPSAwOwogICAgZm9yIChpbnQgaSA9IDEgOyBpIDw9IG4gOyBpKyspewogICAgICAgIGZvciAoaW50IGogPSAwIDsgaiA8PSBuIDsgaisrKSBkcFtpXVtqXSA9IGRwW2kgLSAxXVtqXTsKICAgICAgICBmb3IgKGludCBqID0gMSA7IGogPD0gbiA7IGorKyl7CiAgICAgICAgICAgIGlmIChkcFtpIC0gMV1baiAtIDFdIDw9IHRbaV0pewogICAgICAgICAgICAgICAgZHBbaV1bal0gPSBtaW4oZHBbaV1bal0gLCBkcFtpIC0gMV1baiAtIDFdICsgZltpXSk7CiAgICAgICAgICAgIH0KICAgICAgICB9CiAgICB9CiAgICBmb3IgKGludCBpID0gbiA7IGkgPj0gMCA7IGktLSl7CiAgICAgICAgaWYgKGRwW25dW2ldICE9IGluZil7CiAgICAgICAgICAgIGNvdXQgPDwgaSA8PCAiXG4iOwogICAgICAgICAgICByZXR1cm47CiAgICAgICAgfQogICAgfQp9CgojZGVmaW5lIG5hbWUgIkEiCgppbnQgbWFpbigpewogICAgaW9zX2Jhc2U6OnN5bmNfd2l0aF9zdGRpbygwKTsgY2luLnRpZSgwKTsgY291dC50aWUoMCk7CiAgICBpZiAoZm9wZW4obmFtZSIuSU5QIiAsICJyIikpewogICAgICAgIGZyZW9wZW4obmFtZSIuSU5QIiAsICJyIiAsIHN0ZGluKTsKICAgICAgICBmcmVvcGVuKG5hbWUiLk9VVCIgLCAidyIgLCBzdGRvdXQpOwogICAgfQogICAgaW50IHQgPSAxOyAvL2NpbiA+PiB0OwogICAgd2hpbGUgKHQtLSkgc29sdmUoKTsKICAgIHJldHVybiAwOwp9