✅ [Beats 100%] Swift. Accepted solution
\n\n# Complexity\n- Time complexity:\nO(nlogn)\n\n- Space complexity:\nO(n)\n\n# Code\n\nclass Solution {\n    func maximumValueSum(_ nums: [Int], _ k: Int, _ e
![CleanShot 2024-05-19 at 12.07.17@2x.png](https://assets.leetcode.com/users/images/1dca5358-8508-4cd0-a71e-aec2fa6d7e8d_1716095250.4755497.png)\n\n# Complexity\n- Time complexity:\n$$O(nlogn)$$\n\n- Space complexity:\n$$O(n)$$\n\n# Code\n```\nclass Solution {\n    func maximumValueSum(_ nums: [Int], _ k: Int, _ edges: [[Int]]) -> Int {\n        var delta = nums.map { ($0 ^ k) - $0 }\n        delta.sort(by: >)\n        var res = nums.reduce(0, +)\n        for i in stride(from: 0, to: nums.count, by: 2) {\n            if i == nums.count - 1 {\n                break\n            }\n            var totalDelta = delta[i] + delta[i + 1]\n            if totalDelta <= 0 {\n                break\n            }\n            res += totalDelta\n        }\n        return res\n    }\n}\n```
['Swift']