From 3781a8b1fd26ff06c9413760c27bfc0c7f3af95e Mon Sep 17 00:00:00 2001 From: zzu <90972641+Zuhye@users.noreply.github.com> Date: Sun, 15 Nov 2026 23:49:40 +0900 Subject: [PATCH] 2897. Apply Operations on Array to Maximize Sum of Squares --- ...tions on Array to Maximize Sum of Squares" | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 "leetcode3/\354\206\241\354\243\274\355\230\234/2897. Apply Operations on Array to Maximize Sum of Squares" diff --git "a/leetcode3/\354\206\241\354\243\274\355\230\234/2897. Apply Operations on Array to Maximize Sum of Squares" "b/leetcode3/\354\206\241\354\243\274\355\230\234/2897. Apply Operations on Array to Maximize Sum of Squares" new file mode 100644 index 00000000..cb82c7df --- /dev/null +++ "b/leetcode3/\354\206\241\354\243\274\355\230\234/2897. Apply Operations on Array to Maximize Sum of Squares" @@ -0,0 +1,19 @@ +class Solution: + def maxSum(self, nums: List[int], k: int) -> int: + bins = [0] * 31 + result = [0] * k + + for num in nums: + i = 0 + while num > 0: + if num % 2 == 1: + bins[i] += 1 # 각 수 마다 자리를 증가시킴 + num //= 2 + i+= 1 + + + for i in range(31): + for j in range(min(bins[i], k)): + result[j] += 2 ** i + + return sum(x * x for x in result) % (10**9 + 7)