zoukankan      html  css  js  c++  java
  • 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
    ",ans);
    	return 0;
    }


  • 相关阅读:
    Linux unalias命令 取消别名
    linux cp 拷贝文件或目录
    POJ 1850
    POJ 1844
    POJ 1852
    POJ 1837
    POJ 1833
    POJ 1804
    POJ 1789
    POJ 1781
  • 原文地址:https://www.cnblogs.com/Ren-Ivan/p/7746737.html
Copyright © 2011-2022 走看看