2656. Maximum Sum With Exactly K Elements Solution 1 (time O(n), space O(1)) class Solution(object): def maximizeSum(self, nums, k): """ :type nums: List[int] :type k: int :rtype: int """ return k * (2 * max(nums) + k - 1) // 2