hpnq

TL

May 30th, 2022
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.94 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #define all(x) x.begin(), x.end()
  3. #define pb push_back
  4. using ll = long long;
  5.  
  6. using namespace std;
  7.  
  8.  
  9. vector<int> prime;
  10. int t, n, q, cc, cnt =0, x;
  11.  
  12. int main()
  13. {
  14.     cin >> t;
  15.  
  16.     for(int i = 0; i < t; i++)
  17.     {
  18.         cin >> n >> q;
  19.         vector<int> cnds;
  20.         for(int i = 0; i < n; i++)
  21.         {
  22.             cin >> cc;
  23.             cnds.pb(cc);
  24.         }
  25.         sort(all(cnds), greater<int>());
  26.         for(int j = 0; j < q; j++)
  27.         {
  28.             cin >> x;
  29.             for(auto k: cnds)
  30.             {
  31.                 cnt++;
  32.                 x -= k;
  33.                 if(x <= 0)
  34.                 {
  35.                     break;
  36.                 }
  37.             }
  38.             if(x > 0)
  39.             {
  40.                 cout << -1<< endl;
  41.             }else
  42.             {
  43.                 cout <<cnt << endl;
  44.             }
  45.             cnt = 0;
  46.         }
  47.  
  48.     }
  49.  
  50.     return 0;
  51. }
Advertisement
Add Comment
Please, Sign In to add comment