classSolution{public:intmaximizeSum(vector<int>&nums,intk){// If x = max(nums), ans = x + (x + 1) + .. + (x + k - 1).constintx=ranges::max(nums);returnx*k+k*(k-1)/2;}};
1234567
classSolution{publicintmaximizeSum(int[]nums,intk){// If x = max(nums), ans = x + (x + 1) + .. + (x + k - 1).finalintx=Arrays.stream(nums).max().getAsInt();returnx*k+k*(k-1)/2;}}