public int getMaxSumKElements2(int[] nums, int k) {
if (nums.length < k) {
return -1;
}
int curMax = 0, curSum = 0;
for (int i = 0; i < k; i++) {
curSum += nums[i];
}
curMax = curSum;
for (int i = k, j = 0; i < nums.length; i++, j++) {
curSum = curSum - nums[j];
curSum = curSum + nums[i];
curMax = Math.max(curSum, curMax);
}
return curMax;
}