#C6295. Maximum Sum Contiguous Subsequence

    ID: 50039 Type: Default 1000ms 256MiB

Maximum Sum Contiguous Subsequence

Maximum Sum Contiguous Subsequence

You are given an integer array A of length n and an integer k. Your task is to find the maximum sum of any contiguous subsequence (subarray) of length exactly k.

Formally, you need to compute:

$$\max_{1 \le i \le n-k+1} \sum_{j=i}^{i+k-1} A_j$$

It is guaranteed that n \ge k. Solve this problem using an efficient sliding window or similar approach.

inputFormat

The input is given via standard input (stdin) and consists of two lines:

  • The first line contains two space-separated integers n and k.
  • The second line contains n space-separated integers representing the elements of the array A.

outputFormat

Output the maximum sum of any contiguous subsequence of length k to standard output (stdout) as a single integer.

## sample
5 3
1 2 3 4 5
12