比赛 20160415 评测结果 AAAAAAAAAA
题目名称 烤鸡翅 最终得分 100
用户昵称 咸鱼二号 运行时间 0.215 s
代码语言 C++ 内存使用 2.22 MiB
提交时间 2016-04-15 09:56:05
显示代码纯文本
#include<iostream>
#include<cstring>
#include<cstdio>
#include<string>
#include<algorithm>
#include<cmath>
#include<utility>
#include<cstdlib>
#include<iomanip>	//cout<<setiosflags(ios::fixed)<<setprecision(2);
#include<ctime> //double a=(double)clock();	cout<<a<<endl;
#include<vector>
#include<queue>
using namespace std;
const int maxn=250010;
inline int read(){
	int x=0,ff=1;char ch=getchar();
	while(ch>'9'||ch<'0'){if(ch=='-')ff=-1; ch=getchar();}
	while(ch<='9'&&ch>='0'){x=x*10+ch-'0';ch=getchar();}
	return ff*x;
}
inline long long mymax(long long xx,long long yy)
{if(xx>yy)return xx;return yy;}
int N,a[maxn],b[maxn];
priority_queue<long long,vector<long long>,less<long long> >Q;
long long now=0,temp;
int ans=0;
int main(){
	freopen("wing.in","r",stdin);
	freopen("wing.out","w",stdout);
	N=read();
	for(int i=1;i<=N;i++)
		a[i]=read();
	for(int i=1;i<=N;i++)
		b[i]=read();
	for(int i=1;i<=N;i++){
		now+=a[i];
		if(now>=b[i]){
			ans++,now-=b[i];
			Q.push(b[i]);
		}
		else if(!Q.empty()){
			temp=Q.top();
			if(temp>b[i]){
				now+=temp-b[i];
				Q.pop();
				Q.push(b[i]);
			}
		}
	}
	printf("%d\n",ans);
	return 0;
}