Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- int minimumTransactions(int N, int X, vector<int> &B)
- {
- priority_queue<int> pq;
- for (int i = 0; i < N; i++)
- {
- pq.push(B[i]);
- }
- int res = 0;
- while (pq.top() != 0 && X > 0)
- {
- int temp = pq.top();
- pq.pop();
- X -= temp;
- res++;
- pq.push(temp / 2);
- }
- if (X > 0)
- {
- return -1;
- }
- return res;
- }
- int main()
- {
- int N, X;
- cin >> N >> X;
- vector<int> B(N);
- for (int i = 0; i < N; i++)
- {
- cin >> B[i];
- }
- cout << minimumTransactions(N, X, B) << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment