fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. #define int long long
  5.  
  6. int32_t main(){
  7. ios::sync_with_stdio(false);
  8. cin.tie(nullptr);
  9.  
  10. int T;
  11. cin >> T;
  12.  
  13. while(T--){
  14. int n, k;
  15. cin >> n >> k;
  16.  
  17. vector<int> a(n);
  18. for(int &x : a) cin >> x;
  19.  
  20. vector<int> ans;
  21. bool ok = false;
  22.  
  23. for(int mask = 0; mask < (1 << n); mask++){
  24.  
  25.  
  26. vector<int> b;
  27. vector<bool> used(26);
  28.  
  29. for(int i = 0; i < n; i++){
  30. if(mask >> i & 1){
  31. b.push_back(a[i]);
  32. used[a[i]] = true;
  33. }
  34. }
  35.  
  36. bool good = true;
  37. for(int i = 1; i <= k; i++){
  38. if(!used[i]){
  39. good = false;
  40. break;
  41. }
  42. }
  43.  
  44. if(!good) continue;
  45.  
  46. if(!ok || b < ans){
  47. ans = b;
  48. ok = true;
  49. }
  50. }
  51.  
  52. for(int x : ans) cout << x << ' ';
  53. cout << '\n';
  54. }
  55.  
  56. return 0;
  57. }
Success #stdin #stdout 0s 5320KB
stdin
2
4 3
3 2 1 2
8 4
4 2 3 3 1 3 2 4
stdout
3 1 2 
1 3 2 4