Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #define all(x) x.begin(), x.end()
- #define pb push_back
- using ll = long long;
- using namespace std;
- vector<int> prime;
- int t, n, q, cc, cnt =0, x;
- int main()
- {
- cin >> t;
- for(int i = 0; i < t; i++)
- {
- cin >> n >> q;
- vector<int> cnds;
- for(int i = 0; i < n; i++)
- {
- cin >> cc;
- cnds.pb(cc);
- }
- sort(all(cnds), greater<int>());
- for(int j = 0; j < q; j++)
- {
- cin >> x;
- for(auto k: cnds)
- {
- cnt++;
- x -= k;
- if(x <= 0)
- {
- break;
- }
- }
- if(x > 0)
- {
- cout << -1<< endl;
- }else
- {
- cout <<cnt << endl;
- }
- cnt = 0;
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment