Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- #define ll long long
- const int MOD = 1e9 + 7;
- int f(vector<int> &a)
- {
- set<int> s;
- for(int &i : a)
- {
- s.insert(i);
- }
- return s.size();
- }
- bool comp(pair<int,int> p1, pair<int,int> p2)
- {
- return p2.second > p1.second;
- }
- void solve()
- {
- int n,k;
- cin >> n >> k;
- vector<int> a(n);
- // here I first used unordered map which gave tle
- map<int,int> freq;
- for(int i = 0; i < n; i++)
- {
- cin >> a[i];
- freq[a[i]]++;
- }
- vector<pair<int,int>> fq;
- for(auto &x : freq)
- {
- fq.push_back({x.first,x.second});
- }
- sort(fq.begin(),fq.end(),comp);
- int ct = 0;
- for(auto &x : fq)
- {
- if(k >= x.second)
- {
- k -= x.second;
- ct++;
- }
- }
- cout << max(f(a) - ct,1) << endl;
- }
- int main()
- {
- ios_base::sync_with_stdio(false);
- cin.tie(NULL);
- ll t;
- cin >> t;
- while(t--)
- {
- solve();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement