cogs 2235 烤鸡翅

贪心,每次如果够直接卖,不够找到之前的卖出的最多的一份,然后反悔

不过反悔的确是很好的策略!

#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<queue>
#define N 250005
using namespace std;
priority_queue<long long> q;
long long n,a[N],b[N],ans,now;
int main()
{
	freopen("wing.in","r",stdin);
	freopen("wing.out","w",stdout);
	scanf("%lld",&n);
	for(int i=1;i<=n;i++)
		scanf("%lld",&a[i]);
	for(int i=1;i<=n;i++)
		scanf("%lld",&b[i]);
	for(int i=1;i<=n;i++){
		now+=a[i];
		if(now>=b[i]){
			now-=b[i];
			q.push(b[i]);
			ans++;
		}
		else if(!q.empty()&&q.top()>b[i]){
			now+=q.top();
			now-=b[i];
			q.pop();
			q.push(b[i]);
		}
	}
	printf("%lld\n",ans);
	return 0;
}


posted @ 2017-07-25 21:43  Ren_Ivan  阅读(138)  评论(0编辑  收藏  举报