diff --git "a/leetcode3/\354\265\234\354\233\220\354\244\200/ccccccc2897. Apply Operations on Array to Maximize Sum of Squares.py" "b/leetcode3/\354\265\234\354\233\220\354\244\200/ccccccc2897. Apply Operations on Array to Maximize Sum of Squares.py" new file mode 100644 index 00000000..43741421 --- /dev/null +++ "b/leetcode3/\354\265\234\354\233\220\354\244\200/ccccccc2897. Apply Operations on Array to Maximize Sum of Squares.py" @@ -0,0 +1,24 @@ + +class Solution: + def maxSum(self, nums: list[int], k: int) -> int: + MOD = 10**9 + 7 + bits = [0] * 30 + + for num in nums: + for i in range(30): + if num & (1 << i): + bits[i] += 1 + + ans = 0 + + for _ in range(k): + num = 0 + + for i in range(30): + if bits[i] > 0: + num |= (1 << i) + bits[i] -= 1 + + ans = (ans + num * num) % MOD + + return ans