class Solution: def maxResult(self, nums: List[int], k: int) -> int: List=[] Sum=nums[0] n=len(nums) for i in range(n): j=i+1 while(j<n and j<=i+k): List.append(nums[j]) j=j+1 x=max(List) Sum=Sum+x i=nums.index(x) List.clear() return Sum