C++ Easy Heap Solution.
\nBefore discussing the problem, let me tell you something, it\'s our coding nature \nwhen we see to find max/min sum , element we think of sorting . But what i
```\nBefore discussing the problem, let me tell you something, it\'s our coding nature \nwhen we see to find max/min sum , element we think of sorting . But what if i tell \nyou do sorting but in a better and optimized way, sort only those elements which \nneed to be sorted.\n\nOk let\'s talk about logic to the problem, we have to negate any index element \nk times so array elements yields max sum. So it is clear we have to always \nnegate smallest element, so we can use " min Heap " which will ensure you have \nsmallest element always on top no matter how many insertion or deletion you make.\n```\n```\nclass Solution {\npublic:\n    int find_sum(vector<int>&v, int k){\n        priority_queue<int,vector<int>,greater<int>>q;       // Mean Heap\n        for(int i=0; i<v.size(); i++)\n            q.push(v[i]);\n        while(k){                        // Negate k times ( min element will always be on top )\n            int res = -q.top();\n            q.pop();\n            q.push(res);\n            k--;\n        }\n        int sum = 0;\n        while(!q.empty()){\n            sum += q.top();\n            q.pop();\n        }\n        return sum;\n    }\n    int largestSumAfterKNegations(vector<int>& nums, int k) {\n        int sum = find_sum(nums,k);\n        return sum;\n    }\n};\n```\n```\nLet me tell you a secret, if question is based on array and you feel there is a need of sorting always think of heap solution as a possibility.\n```\nIf you liked my solution please upvote to motivate me. Happy Coding :)\n
['C', 'Sorting', 'Heap (Priority Queue)']