fork download
  1. #include <iostream>
  2. #include <algorithm>
  3. #include <set>
  4. using namespace std;
  5. // to fidn th eminimum # of operations simply count the # of numbers < or equivalent
  6. // bc it is only asking us to output the # of changes, we do not need to perform them making
  7. // this question easy
  8. int main() {
  9. int t;
  10. cin >> t;
  11. while(t--) {
  12. int n,k;
  13. int sol = 0;
  14. cin >> n >> k;
  15. set<int> seen;
  16. for(int i =0;i < n; i++) {
  17. int temp; cin >> temp;
  18. if(temp == k) {
  19. sol++;
  20. }
  21.  
  22. if(0 <= temp && temp < k) {
  23. seen.insert(temp);
  24. }
  25.  
  26. }
  27. int Z = k - (int)seen.size();
  28. int ans = max(sol,Z);
  29. cout << ans << endl;
  30. }
  31. }
Success #stdin #stdout 0.01s 5324KB
stdin
5
1 0
0
3 1
0 2 3
5 5
0 1 2 3 4
6 2
0 3 4 2 6 2
7 4
0 1 5 4 4 7 3
stdout
1
0
0
2
2