From a4df875b4cda22a01507d1021cf3b469b1a6b777 Mon Sep 17 00:00:00 2001 From: chayan das Date: Fri, 23 May 2025 22:26:17 +0530 Subject: [PATCH] Create 3068. Find the Maximum Sum of Node Values1 --- 3068. Find the Maximum Sum of Node Values1 | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 3068. Find the Maximum Sum of Node Values1 diff --git a/3068. Find the Maximum Sum of Node Values1 b/3068. Find the Maximum Sum of Node Values1 new file mode 100644 index 0000000..980ddfe --- /dev/null +++ b/3068. Find the Maximum Sum of Node Values1 @@ -0,0 +1,19 @@ +class Solution { +public: + long long maximumValueSum(vector& nums, int k, vector>& edges) { + long long ans = 0; + int minLoss = INT_MAX; + int canInc = 0; + + for(int i = 0; i < nums.size(); i++){ + if(nums[i] > (nums[i]^k)) ans += nums[i]; + else { + ans += nums[i]^k; + canInc++; + } + minLoss = min(minLoss,abs(nums[i]-(nums[i]^k))); + } + if(canInc % 2 == 0) return ans; + return ans-minLoss; + } +};