fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. #ifdef LOCAL
  5. #include "../debug.cpp"
  6. #else
  7. #define debug(...)
  8. #define debugArr(...)
  9. #endif
  10.  
  11. #define all(x) begin(x), end(x)
  12. #define sz(x) (int)(x).size()
  13. #define ff first
  14. #define ss second
  15. #define pb push_back
  16. #define BIG 998244353
  17. #define MOD 1000000007
  18. #define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
  19. typedef long long ll;
  20. typedef pair<ll, ll> pii;
  21. typedef vector<ll> vi;
  22. typedef vector<pii> vpii;
  23. typedef vector<vi> vvi;
  24.  
  25. void solve() {
  26. int n,m;
  27. cin >> n >> m;
  28.  
  29. vi ast(n);
  30. vpii str(m);
  31. for (int i = 0; i < n; i++)
  32. cin >> ast[i];
  33. for (int i = 0; i < m; i++) {
  34. cin >> str[i].ff;
  35. str[i].ss = i;
  36. }
  37.  
  38. sort(all(ast));
  39.  
  40. for (int i = 0; i < m; i++) {
  41. ll curr = str[i].ff;
  42. int j = 0;
  43. //debug(curr,ast[j]);
  44. while (j < n && curr > ast[j]) {
  45. curr = 2ll*(curr-ast[j]);
  46. curr = min(curr,1ll<<31);
  47. j++;
  48. }
  49.  
  50. //debug(j,curr,ast[j]);
  51. cout << j << " ";
  52. }
  53. cout << "\n";
  54. }
  55.  
  56. int main() {
  57. auto start = chrono::high_resolution_clock::now();
  58. fast_io;
  59. int t;
  60. cin >> t;
  61.  
  62. while (t--) {
  63. solve();
  64. }
  65.  
  66. #ifdef LOCAL
  67. auto end = chrono::high_resolution_clock::now();
  68. chrono::duration<double> duration = end - start;
  69. cerr << "Execution time: " << duration.count() << " seconds" << endl;
  70. #endif
  71. }
  72.  
Success #stdin #stdout 0s 5328KB
stdin
2
4
1 2 3 4
4 3 2 1
3
1 2 2
3 3 1
stdout
1 
1