Advertisement
yicongli

HDU6438

Mar 15th, 2019
226
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.74 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. #define gc c=getchar()
  6. #define r(x) read(x)
  7. #define ll long long
  8.  
  9. template<typename T>
  10. inline void read(T&x){
  11.     x=0;T k=1;char gc;
  12.     while(!isdigit(c)){if(c=='-')k=-1;gc;}
  13.     while(isdigit(c)){x=x*10+c-'0';gc;}x*=k;
  14. }
  15.  
  16. int main(){
  17.     int T;r(T);
  18.     while(T--){
  19.         int n,cnt=0;r(n);
  20.         ll sum=0;
  21.         priority_queue<pair<int,int> >Q;
  22.         for(int i=1;i<=n;++i){
  23.             int x;r(x);
  24.             if(!Q.empty()&&-Q.top().first<x){
  25.                 sum+=x+Q.top().first;
  26.                 if(!Q.top().second)cnt+=2;
  27.                 Q.pop();
  28.                 Q.push(make_pair(-x,1));
  29.             }
  30.             Q.push(make_pair(-x,0));
  31.         }
  32.         printf("%lld %d\n",sum,cnt);
  33.     }
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement