From fd5b418714517b1cca4bd4bacd6c4b9b2749cdfc Mon Sep 17 00:00:00 2001 From: Won Joon Thomas Choi <113500771+724thomas@users.noreply.github.com> Date: Sun, 15 Nov 2026 23:09:46 +0900 Subject: [PATCH] Create ccccccc2897. Apply Operations on Array to Maximize Sum of Squares.py --- ...ns on Array to Maximize Sum of Squares.py" | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 "leetcode3/\354\265\234\354\233\220\354\244\200/ccccccc2897. Apply Operations on Array to Maximize Sum of Squares.py" 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