Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 1160 Accepted Submission(s): 369
1 #include<bits/stdc++.h> 2 using namespace std; 3 #define LL long long 4 map<int,int>M; 5 int main(){ 6 int t,n,m,i,j,k,a; 7 cin>>t; 8 while(t--){ 9 scanf("%d",&n); 10 priority_queue<int,vector<int>,greater<int> >q; 11 M.clear(); 12 LL s1=0,s2=0; 13 for(i=1;i<=n;++i){ 14 scanf("%d",&a); 15 if(q.empty() || q.top()>=a){ 16 q.push(a); 17 } 18 else{ 19 s1+=a-q.top(); 20 if(M[q.top()]==0){ 21 s2++; 22 } 23 else{ 24 M[q.top()]--; 25 } 26 q.pop(); 27 q.push(a); 28 q.push(a); 29 M[a]++; 30 } 31 32 } 33 //cout<<s1<<endl; 34 printf("%lld %lld\n",s1,s2*2); 35 } 36 return 0; 37 }
原文:https://www.cnblogs.com/zzqc/p/9537656.html