Priority_queue max heap vs min heap
Intuition\n Describe your first thoughts on how to solve this problem. \nUse a max heap(priority_queue) to solve.\n 2nd approach uses a min heap.\n# Approach\n 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nUse a max heap(priority_queue) to solve.\n 2nd approach uses a min heap.\n# Approach\n<!-- Describe your approach to solving the problem. -->\nFind the k largest elements using a max heap\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n$$O(n+k\\log n)$$\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n$$O(n)$$\n# Code\n```\n#pragma GCC optimize("O3", "unroll-loops")\nclass Solution {\npublic:\n    long long maximumHappinessSum(vector<int>& happiness, int k) {\n        int n=happiness.size();\n        priority_queue<int> pq(happiness.begin(), happiness.end());//maxheap\n        long long sum=0;\n        for(int i=0; i<k; i++){\n            long long x=max(0, pq.top()-i);\n        //    cout<<x<<endl;\n            pq.pop();\n            sum+=x;\n        }\n            \n        return sum;\n        \n    }\n};\n\n```\n# C++ using min heap\n```\n#pragma GCC optimize("O3", "unroll-loops")\nclass Solution {\npublic:\n    long long maximumHappinessSum(vector<int>& happiness, int k) {\n        int n=happiness.size();\n        priority_queue<int, vector<int>, greater<int>> pq(happiness.begin(), happiness.begin()+k);//minheap\n        for(int i=k; i<n; i++){\n            pq.push(happiness[i]);\n            pq.pop();\n        }\n        long long sum=0;\n        for(int i=k-1; i>=0; i--){\n            long long x=max(0, pq.top()-i);\n        //    cout<<x<<endl;\n            pq.pop();\n            sum+=x;\n        }\n        return sum;\n        \n    }\n};\n```
['Heap (Priority Queue)', 'C++']