Subscribe Us

Responsive Advertisement

Advertisement

Monk and the Magical Candy Bags hackerearth solution

 

Monk and the Magical Candy Bags hackerearth solution
https://www.hackerearth.com/practice/data-structures/trees/heapspriority-queues/practice-problems/algorithm/monk-and-the-magical-candy-bags/




#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int main()
{
ios_base::sync_with_stdio(0);

cin.tie(0);

cout.tie(0);
ll t,n,i,j,ans,r,c,k,a;
cin>>t;
while(t--)
{
    c=0;
    multiset<ll> st;
cin>>n>>k;
for(i=0;i<n;i++)
{
    cin>>a;
st.insert(a);
}
for(i=0;i<k;i++)
{
    auto it=st.end();
    it--;

c+=(*it);
r=(*it)/2;
st.erase(it);
st.insert(r);
}

cout<<c<<endl;

}

return 0;
}

Post a Comment

0 Comments