Advertisement
Guest User

Untitled

a guest
Aug 17th, 2019
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.03 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. #define ll long long
  3. #define f first
  4. #define s second
  5. #define pb push_back
  6. using namespace std;
  7. ll n,t,x,ans,y,a[2000005],b[1000005],adans;
  8. int DecreasingArray() {
  9. int sum = 0, dif = 0;
  10. priority_queue<int, vector<int>, greater<int> > pq;
  11. for (int i = 1; i <= 2*n; i++) {
  12. if (!pq.empty() && pq.top() < a[i]) {
  13. dif = a[i] - pq.top();
  14. sum += dif;
  15. pq.pop();
  16. pq.push(a[i]);
  17. }
  18. pq.push(a[i]);
  19. }
  20. return sum;
  21. }
  22. int main(){
  23. ios::sync_with_stdio(false);
  24. cin >> t;
  25.  
  26. while(t--){
  27. cin >> n;
  28. adans = 0;
  29. for(int i=1; i<=n; i++){
  30. cin >> b[i];
  31. if(b[i] > 2*n){
  32. adans++;
  33. }
  34. else {
  35. a[b[i]]++;
  36. }
  37. }
  38. cout << DecreasingArray() + adans << endl;
  39. for(int i=1; i<=n; i++){
  40. if(b[i] <= 2*n)a[b[i]] = 0;
  41. }
  42. }
  43.  
  44.  
  45.  
  46.  
  47.  
  48. return 0;
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement