Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- int main()
- {
- int n, k, operations=0;
- cout<<"Enter value of k & n"<<endl;
- cin >> n >> k;
- cout<<"Enter values"<<endl;
- priority_queue<int, vector<int>, greater<int> > pq;
- for (int i=0; i<n; i++)
- {
- int a;
- cin>>a;
- pq.push(a);
- }
- while (pq.top()<k && pq.size()>=2)
- {
- int cookie1=pq.top();
- pq.pop();
- int cookie2=pq.top();
- pq.pop();
- pq.push(cookie1+2*cookie2);
- operations++;
- }
- if(pq.top()>=k)
- cout<<operations;
- else
- cout<<"-1";
- }
Advertisement
Add Comment
Please, Sign In to add comment