#K1766. Maximum Sum Subarray Count
Maximum Sum Subarray Count
Maximum Sum Subarray Count
You are given an array of \(N\) integers and an integer \(K\). Your task is to find the number of contiguous subarrays of length exactly \(K\) that have the maximum possible sum among all contiguous subarrays of that length.
More formally, let \(A = [a_1, a_2, \dots, a_N]\) be the array. Consider all subarrays \(A[i \dots i+K-1]\) for \(1 \le i \le N-K+1\), and let \(S_i = \sum_{j=0}^{K-1} a_{i+j}\). Let \(S_{max} = \max_{1 \le i \le N-K+1} S_i\). You are required to output the count of \(i\)'s for which \(S_i = S_{max}\).
Note: The input is provided via standard input (stdin) and the output should be written to standard output (stdout).
inputFormat
The input is read from standard input and has the following format:
N K a1 a2 a3 ... aN
Where:
- N is the number of elements in the array.
- K is the length of the subarrays to consider.
- a1, a2, ..., aN are the integer elements of the array.
outputFormat
The output is a single integer printed to standard output which is the number of contiguous subarrays of length \(K\) that have the maximum sum.
## sample7 3
1 2 3 4 5 6 7
1