Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution {
- public:
- int minStoneSum(vector<int>& piles, int k) {
- priority_queue<int> pq;
- for(auto pile: piles){
- pq.push(pile);
- }
- long long int sum = accumulate(piles.begin(), piles.end(), 0LL);
- long long int ans = 0;
- while(k && !pq.empty()){
- int t = pq.top(); pq.pop();
- int half = t/2;
- ans += half;
- t -= half;
- if(t)
- pq.push(t);
- k--;
- }
- return sum-ans;
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement