Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- #define ll long long
- #define f first
- #define s second
- #define pb push_back
- using namespace std;
- ll n,t,x,ans,y,a[2000005],b[1000005],adans;
- int DecreasingArray() {
- int sum = 0, dif = 0;
- priority_queue<int, vector<int>, greater<int> > pq;
- for (int i = 1; i <= 2*n; i++) {
- if (!pq.empty() && pq.top() < a[i]) {
- dif = a[i] - pq.top();
- sum += dif;
- pq.pop();
- pq.push(a[i]);
- }
- pq.push(a[i]);
- }
- return sum;
- }
- int main(){
- ios::sync_with_stdio(false);
- cin >> t;
- while(t--){
- cin >> n;
- adans = 0;
- for(int i=1; i<=n; i++){
- cin >> b[i];
- if(b[i] > 2*n){
- adans++;
- }
- else {
- a[b[i]]++;
- }
- }
- cout << DecreasingArray() + adans << endl;
- for(int i=1; i<=n; i++){
- if(b[i] <= 2*n)a[b[i]] = 0;
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement