HDU5988

#include<queue>
#include<cstdio>
#include<iostream>
using namespace std;
#define LL long long
struct LLC{
    int v;
    int flag;
    bool operator < (const LLC & a) const{
        if(v == a.v)
            return !flag;
        return v > a.v;
    }
};
int main(){
    int t;
    scanf("%d", &t);
    while(t--){
        int n;
        scanf("%d", &n);
        LLC tra;//trader
        LLC sell;
        priority_queue<LLC> q;
        LL time = 0, val = 0;
        for(int i = 1; i <= n; i++){
            scanf("%d", &tra.v);
            tra.flag = 0;
            if(i == 1){ q.push(tra); continue;}
            sell = q.top();
            if(tra.v > sell.v){
                q.pop();
                val += (LL)(tra.v - sell.v);
                    if(sell.flag == 0){
                        time = time + 1;
                    }
                    else{
                        sell.flag = 0;
                        q.push(sell);
                    }
                tra.flag = 1;
                   // q.push(tra);
            }
            q.push(tra);
        }
        while(!q.empty()) q.pop();
        printf("%lld %lld\n", val, time*2);
    }
    return 0;
}
 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章