Easy C++ Solution | Beats 100 💯✅
Intuition\n Describe your first thoughts on how to solve this problem. \nThe problem involves maximizing the sum of a vector v of integers by performing a bitwi
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThe problem involves maximizing the sum of a vector v of integers by performing a bitwise XOR operation with an integer k on some or all of the elements. The aim is to determine the optimal approach to achieve the maximum possible sum of the modified vector.\n# Approach\n<!-- Describe your approach to solving the problem. -->\n1. Initial Total Sum: Calculate the initial sum of all elements in the vector v.\n2. Difference Calculation: For each element p in the vector, compute the difference diff between the XOR result (p ^ k) and the original value p.\n3. Positive Differences: Focus on differences that are positive (diff > 0) as they represent an increase in the sum when the XOR operation is applied.\n4. Total Difference: Accumulate the total positive differences to determine the potential increase in the sum.\n5. Handling Odd Positive Count: If the number of positive differences is odd, adjust by subtracting the smallest absolute difference to ensure the result is maximized.\n\n# Complexity\n- Time complexity: O(n)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: O(1)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\npublic:\n    long long maximumValueSum(vector<int>& v, int k, vector<vector<int>>& edges) {\n        long long total = accumulate(v.begin(), v.end(), 0ll);\n        \n        long long totalDiff = 0;\n        long long diff;\n        int positiveCount = 0;\n        long long minDiff = numeric_limits<int>::max();\n        for(auto p : v)\n        {\n            diff = (p^k) - p;\n            \n            if(diff > 0)\n            {\n                totalDiff += diff;\n                positiveCount++;\n            }\n            minDiff = min(minDiff, abs(diff));\n        }\n        if(positiveCount % 2 == 1)\n        {\n            totalDiff = totalDiff - minDiff;\n        }\n        return total + totalDiff;\n    }\n};\n```
['Bit Manipulation', 'Tree', 'C++']