// PhuThuyRuntime <3
// A secret makes a woman woman
#include <bits/stdc++.h>
using namespace std;
#define eb emplace_back
#define ef emplace_front
#define pb push_back
#define pf push_front
#define all(v) v.begin(), v.end()
#define ins insert
#define lb lower_bound
#define ub upper_bound
#define fo(i, l, r) for(int i = l; i <= r; i++)
#define foi(i, l, r) for(int i = l; i >= r; i--)
#define elif else if
#define el cout << "\n";
#define pii pair<int, int>
#define pli pair<ll, int>
#define pll pair<ll, ll>
#define pil pair<int, ll>
#define fi first
#define se second
#define in(x) freopen(x, "r", stdin)
#define out(x) freopen(x, "w", stdout)
#define ll long long
#define ull unsigned long long
#define pob pop_back
#define bs binary_search
#define vi vector<int>
#define vii vector<pair<int, int>>
#define getbit(i, j) ((i >> j) & 1)
#define offbit(i, j) ((1LL << j) ^ i)
#define onbit(i, j) ((1LL << j) | i)
const int N = 1e5 + 2;
const ll mod = 1e9 + 7;
const int inf = INT_MAX;
const int base = 31;
const long double EPS = 1e-9;
const long double pi = acos(-1.0);
int n;
pll a[N];
void inp(){
cin >> n;
fo(i, 1, n) cin >> a[i].se;
fo(i, 1, n) cin >> a[i].fi;
}
bool cmp(pll a, pll b){
return a.fi + a.se < b.fi + b.se;
}
void sol(){
sort(a + 1, a + n + 1, cmp);
priority_queue<ll> q;
ll cur = 0;
int ans = 0;
fo(i, 1, n){
if(cur <= a[i].fi){
cur += a[i].se;
q.push(a[i].se);
ans++;
}
else{
if(!q.empty() and a[i].se < q.top()){
cur -= q.top() - a[i].se;
q.pop();
q.push(a[i].se);
}
}
}
cout << ans;
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
inp();
sol();
return 0;
}