#include <bits/stdc++.h>
#define FOR(i, l, r) for (int i = l; i <= r; ++i)
#define FOD(i, r, l) for (int i = r; i >= l; --i)
#define ll long long
#define ep emplace_back
#define fi first
#define se second
#define pli pair <ll, int>
#define NAME ""
#define all(x) x.begin(), x.end()
using namespace std;
const int N = 5e5 + 5;
const ll INF = 2e9;
int n;
ll t[N], f[N];
priority_queue <ll> pq;
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
if (fopen(NAME".INP", "r"))
{
freopen(NAME".INP", "r", stdin);
freopen(NAME".OUT", "w", stdout);
}
cin >> n;
FOR(i, 1, n) cin >> t[i];
FOR(i, 1, n) cin >> f[i];
ll D = 0;
FOR(i, 1, n)
{
if (D <= t[i])
{
pq.push(f[i]);
D += f[i];
}
else
{
ll fj = pq.top();
if (fj > f[i])
{
pq.pop();
D = D - fj + f[i];
pq.push(f[i]);
}
}
}
cout << pq.size();
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CiNkZWZpbmUgRk9SKGksIGwsIHIpIGZvciAoaW50IGkgPSBsOyBpIDw9IHI7ICsraSkKI2RlZmluZSBGT0QoaSwgciwgbCkgZm9yIChpbnQgaSA9IHI7IGkgPj0gbDsgLS1pKQojZGVmaW5lIGxsIGxvbmcgbG9uZwojZGVmaW5lIGVwIGVtcGxhY2VfYmFjawojZGVmaW5lIGZpIGZpcnN0CiNkZWZpbmUgc2Ugc2Vjb25kCiNkZWZpbmUgcGxpIHBhaXIgPGxsLCBpbnQ+CiNkZWZpbmUgTkFNRSAiIgojZGVmaW5lIGFsbCh4KSB4LmJlZ2luKCksIHguZW5kKCkKdXNpbmcgbmFtZXNwYWNlIHN0ZDsKCmNvbnN0IGludCBOID0gNWU1ICsgNTsKY29uc3QgbGwgSU5GID0gMmU5OwoKaW50IG47CmxsIHRbTl0sIGZbTl07CnByaW9yaXR5X3F1ZXVlIDxsbD4gcHE7CgpzaWduZWQgbWFpbigpCnsKICAgIGlvc19iYXNlOjpzeW5jX3dpdGhfc3RkaW8oZmFsc2UpOwogICAgY2luLnRpZShOVUxMKTsKICAgIGlmIChmb3BlbihOQU1FIi5JTlAiLCAiciIpKQogICAgewogICAgICAgIGZyZW9wZW4oTkFNRSIuSU5QIiwgInIiLCBzdGRpbik7CiAgICAgICAgZnJlb3BlbihOQU1FIi5PVVQiLCAidyIsIHN0ZG91dCk7CiAgICB9CiAgICBjaW4gPj4gbjsKICAgIEZPUihpLCAxLCBuKSBjaW4gPj4gdFtpXTsKICAgIEZPUihpLCAxLCBuKSBjaW4gPj4gZltpXTsKICAgIGxsIEQgPSAwOwogICAgRk9SKGksIDEsIG4pCiAgICB7CiAgICAgICAgaWYgKEQgPD0gdFtpXSkKICAgICAgICB7CiAgICAgICAgICAgIHBxLnB1c2goZltpXSk7CiAgICAgICAgICAgIEQgKz0gZltpXTsKICAgICAgICB9CiAgICAgICAgZWxzZQogICAgICAgIHsKICAgICAgICAgICAgbGwgZmogPSBwcS50b3AoKTsKICAgICAgICAgICAgaWYgKGZqID4gZltpXSkKICAgICAgICAgICAgewogICAgICAgICAgICAgICAgcHEucG9wKCk7CiAgICAgICAgICAgICAgICBEID0gRCAtIGZqICsgZltpXTsKICAgICAgICAgICAgICAgIHBxLnB1c2goZltpXSk7CiAgICAgICAgICAgIH0KICAgICAgICB9CiAgICB9CiAgICBjb3V0IDw8IHBxLnNpemUoKTsKICAgIHJldHVybiAwOwp9Cg==