fork(1) download
  1. // #include <bits/stdc++.h>
  2. // using namespace std;
  3.  
  4. // #define int long long int
  5.  
  6. // int32_t main() {
  7. // ios_base::sync_with_stdio(false);
  8. // cin.tie(nullptr);
  9.  
  10. // int t;
  11. // t = 1;
  12. // // cin >> t;
  13. // while (t--) {
  14. // int n;
  15. // cin >> n;
  16. // int k;
  17. // cin >> k;
  18. // int A[n];
  19. // for (int i = 0; i < n; i++) {
  20. // cin >> A[i];
  21. // }
  22. // map<int,int> m;
  23. // for(int i=0;i<n;i++){
  24. // m[A[i]]=1;
  25. // }
  26. // int B[k];
  27. // for (int i = 0; i < k; i++) {
  28. // cin >> B[i];
  29. // }
  30. // sort(A, A + n);
  31. // for(int i=0,j=0;i<n&&j<k;){
  32. // if(A[i]>B[j]&&m[A[i]]==1){
  33. // if(i==0){
  34. // cout << -1 << endl;
  35. // }
  36. // else{
  37. // cout << A[i-1] << endl;
  38. // m[A[i-1]]=0;
  39. // i=0;
  40. // j++;
  41. // }
  42.  
  43. // }
  44. // else if(A[i]==B[j]&&m[A[i]]==1){
  45. // cout << A[i] << endl;
  46. // m[A[i]]=0;
  47. // i=0;
  48. // j++;
  49. // }
  50. // else{
  51. // i++;
  52. // }
  53. // }
  54. // }
  55. // return 0;
  56. // }
  57. // #include <bits/stdc++.h>
  58. // using namespace std;
  59.  
  60. // #define int long long int
  61.  
  62. // int32_t main() {
  63. // ios_base::sync_with_stdio(false);
  64. // cin.tie(nullptr);
  65.  
  66. // int n;
  67. // cin >> n;
  68. // int k;
  69. // cin >> k;
  70.  
  71. // int A[n];
  72. // for (int i = 0; i < n; i++) {
  73. // cin >> A[i];
  74. // }
  75.  
  76. // map<int, int> m;
  77. // for (int i = 0; i < n; i++) {
  78. // m[A[i]] = 1;
  79. // }
  80.  
  81. // int B[k];
  82. // for (int i = 0; i < k; i++) {
  83. // cin >> B[i];
  84. // }
  85.  
  86. // sort(A, A + n);
  87.  
  88. // for (int i = 0, j = 0; i < n && j < k;) {
  89. // if (A[i] > B[j] && m[A[i]] == 1) {
  90. // if (i == 0) {
  91. // cout << -1 << endl;
  92. // } else {
  93. // cout << A[i - 1] << endl;
  94. // m[A[i - 1]] = 0;
  95. // j++;
  96. // }
  97. // } else if (A[i] == B[j] && m[A[i]] == 1) {
  98. // cout << A[i] << endl;
  99. // m[A[i]] = 0;
  100. // j++;
  101. // } else {
  102. // i++;
  103. // }
  104. // }
  105.  
  106. // return 0;
  107. // }
  108. #include <iostream>
  109. #include <vector>
  110. #include <algorithm>
  111.  
  112. using namespace std;
  113.  
  114. int main() {
  115. ios_base::sync_with_stdio(false);
  116. cin.tie(nullptr);
  117.  
  118. int t;
  119. cin >> t;
  120.  
  121. while (t--) {
  122. int n, k;
  123. cin >> n >> k;
  124.  
  125. vector<int> tickets(n);
  126. for (int i = 0; i < n; i++) {
  127. cin >> tickets[i];
  128. }
  129.  
  130. sort(tickets.begin(), tickets.end());
  131.  
  132. for (int i = 0; i < k; i++) {
  133. int maxPrice;
  134. cin >> maxPrice;
  135.  
  136. int index = -1;
  137. for (int j = 0; j < n; j++) {
  138. if (tickets[j] > maxPrice) {
  139. break;
  140. }
  141. index = j;
  142. }
  143.  
  144. if (index == -1) {
  145. cout << -1 << endl;
  146. } else {
  147. cout << tickets[index] << endl;
  148. tickets.erase(tickets.begin() + index);
  149. n--;
  150. }
  151. }
  152. }
  153.  
  154. return 0;
  155. }
  156.  
Success #stdin #stdout 0.01s 5408KB
stdin
5 3
5 3 7 8 5
4 8 3
stdout
3
-1
8
-1
-1
0
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1