Team Ai
Datasetpublic

FPEvalRepoPublic/LeetCodeMetaData

sourceHugging Faceupdated 9mo agoView on Hugging Face
0likes399downloads
maximum-sum-with-exactly-k-elements.json30 linesDownload Raw Back to root
1{2  "id": 2767,3  "name": "maximum-sum-with-exactly-k-elements",4  "difficulty": "Easy",5  "link": "https://leetcode.com/problems/maximum-sum-with-exactly-k-elements/",6  "date": "2023-04-15",7  "task_description": "You are given a **0-indexed** integer array `nums` and an integer `k`. Your task is to perform the following operation **exactly** `k` times in order to maximize your score: Select an element `m` from `nums`. Remove the selected element `m` from the array. Add a new element with a value of `m + 1` to the array. Increase your score by `m`. Return _the maximum score you can achieve after performing the operation exactly_ `k` _times._ **Example 1:** ``` **Input:** nums = [1,2,3,4,5], k = 3 **Output:** 18 **Explanation:** We need to choose exactly 3 elements from nums to maximize the sum. For the first iteration, we choose 5. Then sum is 5 and nums = [1,2,3,4,6] For the second iteration, we choose 6. Then sum is 5 + 6 and nums = [1,2,3,4,7] For the third iteration, we choose 7. Then sum is 5 + 6 + 7 = 18 and nums = [1,2,3,4,8] So, we will return 18. It can be proven, that 18 is the maximum answer that we can achieve. ``` **Example 2:** ``` **Input:** nums = [5,5,5], k = 2 **Output:** 11 **Explanation:** We need to choose exactly 2 elements from nums to maximize the sum. For the first iteration, we choose 5. Then sum is 5 and nums = [5,5,6] For the second iteration, we choose 6. Then sum is 5 + 6 = 11 and nums = [5,5,7] So, we will return 11. It can be proven, that 11 is the maximum answer that we can achieve. ``` **Constraints:** `1 <= nums.length <= 100` `1 <= nums[i] <= 100` `1 <= k <= 100`",8  "test_case": [9    {10      "label": "Example 1",11      "input": "nums = [1,2,3,4,5], k = 3",12      "output": "18 "13    },14    {15      "label": "Example 2",16      "input": "nums = [5,5,5], k = 2",17      "output": "11 "18    }19  ],20  "constraints": [21    "1 <= nums.length <= 100",22    "1 <= nums[i] <= 100",23    "1 <= k <= 100"24  ],25  "python_template": "class Solution(object):\n    def maximizeSum(self, nums, k):\n        \"\"\"\n        :type nums: List[int]\n        :type k: int\n        :rtype: int\n        \"\"\"\n        ",26  "java_template": "class Solution {\n    public int maximizeSum(int[] nums, int k) {\n        \n    }\n}",27  "metadata": {28    "func_name": "maximizeSum"29  }30}