#C5952. Maximum Points

    ID: 49658 Type: Default 1000ms 256MiB

Maximum Points

Maximum Points

You are given n problems, each associated with a certain number of points. Your task is to select exactly k contiguous problems to maximize the total number of points earned. Note that some problems may have negative point values.

Formally, given an integer \( n \) and an integer \( k \) (with \( 1 \leq k \leq n \)), along with an array \( points \) of length \( n \), find the maximum sum of any contiguous subarray of length \( k \). Mathematically, the problem is to compute:

\( \max_{0 \leq i \leq n-k} \sum_{j=i}^{i+k-1} points[j] \)

If \( k = n \), then the answer is simply the sum of all points.

inputFormat

The input consists of two lines:

  • The first line contains two space-separated integers, \( n \) and \( k \), where \( 1 \leq k \leq n \leq 10^5 \).
  • The second line contains \( n \) space-separated integers representing the points of each problem.

outputFormat

Output a single integer: the maximum total points that can be earned by choosing exactly \( k \) contiguous problems.

## sample
5 3
1 2 3 -4 5
6

</p>