zoukankan      html  css  js  c++  java
  • HDU 6438 Buy and Resell

    高卖低买,可以交易多次

    维护一个优先队列,贪心

    相当于每天卖出

    用当前元素减优先队列最小得到收益

    用0/卖出,1/买入标志是否真实进行了交易,记录次数

    #include<bits/stdc++.h>
    using namespace std;
    typedef long long ll;
    ll A[500005];
    #define P pair<ll,ll>
    priority_queue<P,vector<P>,greater<P> > q;
    int main()
    {
        int T,N;
        scanf("%d",&T);
        while(T--){
            scanf("%d",&N);
            ll ans=0,t,tt=0;
            while(!q.empty())q.pop();
            for(int i=0;i<N;i++){
                scanf("%lld",&A[i]);
                q.push(P(A[i],0));
                q.push(P(A[i],1));
                t=A[i]-q.top().first;
                if(q.top().second==1)tt+=2;
                q.pop();
                ans+=t;
    
            }
            cout<<ans<<' '<<tt<<'
    ';
        }
    }
  • 相关阅读:
    蒟蒻的填坑计划
    现在的状态....
    date modify
    set source
    image source
    simple auth
    net
    bridge
    iptable
    namespace
  • 原文地址:https://www.cnblogs.com/liulex/p/11367476.html
Copyright © 2011-2022 走看看