fork(1) download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. // Speed
  5. #define fast_io ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
  6.  
  7. // Typedefs
  8. #define int long long
  9. #define pb push_back
  10. #define ff first
  11. #define ss second
  12. #define all(x) (x).begin(), (x).end()
  13. #define rall(x) (x).rbegin(), (x).rend()
  14. #define sz(x) ((int)(x).size())
  15. #define endl '\n'
  16.  
  17. // Loops
  18. #define rep(i,a,b) for(int i=a;i<b;++i)
  19. #define each(x, a) for (auto &x : a)
  20.  
  21. void solve() {
  22. int n;
  23. cin >> n;
  24.  
  25. vector<int> a(n);
  26. unordered_map<int,int> freq;
  27.  
  28. rep(i,0,n) {
  29. cin >> a[i];
  30. freq[a[i]]++;
  31. }
  32.  
  33. int kept = 0;
  34.  
  35. for (auto &p : freq) {
  36. int v = p.first;
  37. int f = p.second;
  38.  
  39. if (f < v) {
  40. }
  41. else {
  42. kept += v;
  43. }
  44. }
  45.  
  46. cout << (n - kept) << endl;
  47. }
  48.  
  49. int32_t main() {
  50. fast_io;
  51. int t;
  52. cin >> t;
  53. while (t--) solve();
  54. return 0;
  55. }
  56.  
Success #stdin #stdout 0s 5320KB
stdin
4
3
1 2 2
5
1 1 2 2 3
10
1 2 3 2 4 4 4 4 5 2
1
0
stdout
0
2
3
1