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)