#C989. Maximum Sum Subarray of Size K

    ID: 54032 Type: Default 1000ms 256MiB

Maximum Sum Subarray of Size K

Maximum Sum Subarray of Size K

Given an array of integers and an integer ( k ), your task is to find the maximum sum of any contiguous subarray of length exactly ( k ). This problem can be solved efficiently using the sliding window technique.

For example, if the array is [1, 2, 3, 4, 5] and ( k = 3 ), the maximum sum is 12, achieved by the subarray [3, 4, 5].

inputFormat

The input is provided via standard input (stdin).

The first line contains an integer ( n ) representing the number of elements in the array. The second line contains ( n ) space-separated integers. The third line contains an integer ( k ) which is the length of the subarray.

outputFormat

Output a single integer to standard output (stdout), representing the maximum sum of any contiguous subarray of length exactly ( k ).## sample

5
1 2 3 4 5
3
12

</p>