| 记录编号 | 
        251024 | 
        评测结果 | 
        AAAAAAAAAA | 
    
    
        | 题目名称 | 
        2235.烤鸡翅 | 
        最终得分 | 
        100 | 
            
    
    
        | 用户昵称 | 
         dydxh | 
        是否通过 | 
        通过 | 
    
    
        | 代码语言 | 
        C++ | 
        运行时间 | 
        0.153 s  | 
    
    
        | 提交时间 | 
        2016-04-16 17:31:59 | 
        内存使用 | 
        2.22 MiB  | 
        
    
    
    
    		显示代码纯文本
		
		/*
Problem:Wing;
Language:c++;
by dydxh;
Date:2016.04.15;
*/
#include<algorithm>
#include<iostream>
#include<cstring>
#include<utility>
#include<cstdlib>
#include<cstdio>
#include<string>
#include<vector>
#include<ctime>
#include<cmath>
#include<queue>
#include<map>
#include<set>
#define ll long long
#define ull unsigned long long
using namespace std;
const int oo=2000000000;
const int maxn=250005;
int n,Ans;
ll Lefter;
int x[maxn],y[maxn];
priority_queue<int,vector<int>,less<int> >Q;
inline int read(){
	int x=0;bool flag=false;char ch=getchar();
	while(ch>'9' || ch<'0'){if(ch=='-') flag=true;ch=getchar();}
	while(ch>='0' && ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return flag?-x:x;
}
int main(){
	//freopen("cc.in","r",stdin);
	freopen("wing.in","r",stdin);
	freopen("wing.out","w",stdout);
	n=read();
	for(int i=1;i<=n;i++) x[i]=read();
	for(int i=1;i<=n;i++) y[i]=read();
	for(int i=1;i<=n;i++){
		Lefter+=x[i];
		if(Lefter>=y[i]){
			Lefter-=y[i],Ans++;
			Q.push(y[i]);
		}
		else if(Q.empty()==false){
			int Maxx=Q.top();
			if(Maxx>y[i]){
				Q.pop(),Q.push(y[i]);
				Lefter+=Maxx-y[i];
			}
		}
	}
	cout<<Ans<<endl;
	//cout<<"Time has passed:"<<1.0*clock()/1000<<"s!"<<endl;
    return 0;
}