#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
typedef pair<int,int> pii;
const int MaxN = 1e6+7;
int n;
pii a[MaxN];
bool cmp(pii a,pii b) {
return a.fi + a.se < b.fi + b.se;
}
int main() {
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin >> n;
for (int i=1;i<=n;i++) cin >> a[i].fi;
for (int i=1;i<=n;i++) cin >> a[i].se;
sort(a+1,a+n+1,cmp);
int strong = 0;
priority_queue<int> pq;
for (int i=1;i<=n;i++) {
strong += a[i].fi;
pq.push(a[i].fi);
if (strong > a[i].se + a[i].fi) {
strong -= pq.top();
pq.pop();
}
}
cout << pq.size();
}