#K92252. Maximum Sales of Consecutive Days

    ID: 38156 Type: Default 1000ms 256MiB

Maximum Sales of Consecutive Days

Maximum Sales of Consecutive Days

You are given a list of daily sales and an integer k. Your task is to find the maximum total sales over any period of k consecutive days using an efficient sliding window approach.

In mathematical terms, for a sales array \(S\) and an integer window length \(k\), you need to compute and maximize the sum \(\sum_{i=0}^{k-1} S_{j+i}\) where \(0 \leq j \leq n-k\).

Be sure to handle possible negative values in the sales data correctly.

inputFormat

The input consists of two lines:

  • The first line contains two integers n and k, where n (1 ≤ n ≤ 105) is the number of days and k (1 ≤ k ≤ n) is the number of consecutive days.
  • The second line contains n space-separated integers representing the daily sales.

outputFormat

Output a single integer which is the maximum sum of sales over any k consecutive days.

## sample
6 3
10 20 30 40 50 60
150