Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- #define gc c=getchar()
- #define r(x) read(x)
- #define ll long long
- template<typename T>
- inline void read(T&x){
- x=0;T k=1;char gc;
- while(!isdigit(c)){if(c=='-')k=-1;gc;}
- while(isdigit(c)){x=x*10+c-'0';gc;}x*=k;
- }
- int main(){
- int T;r(T);
- while(T--){
- int n,cnt=0;r(n);
- ll sum=0;
- priority_queue<pair<int,int> >Q;
- for(int i=1;i<=n;++i){
- int x;r(x);
- if(!Q.empty()&&-Q.top().first<x){
- sum+=x+Q.top().first;
- if(!Q.top().second)cnt+=2;
- Q.pop();
- Q.push(make_pair(-x,1));
- }
- Q.push(make_pair(-x,0));
- }
- printf("%lld %d\n",sum,cnt);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment