#K42167. Maximum Temperature Sum over k Continuous Hours

    ID: 27028 Type: Default 1000ms 256MiB

Maximum Temperature Sum over k Continuous Hours

Maximum Temperature Sum over k Continuous Hours

Given an array of integers representing temperatures recorded at each hour, the task is to find the maximum sum of temperatures over any continuous block of k hours. Formally, if the temperatures are represented as an array \(T = [T_1, T_2, \dots, T_n]\), you are to compute:

\(\max_{1 \leq i \leq n-k+1} \left\{ \sum_{j=i}^{i+k-1} T_j \right\}\)

It is guaranteed that n and k are positive integers and k ≤ n.

inputFormat

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

  • The first line contains two integers n and k separated by a space, where n is the number of hours and k is the number of consecutive hours to consider.
  • The second line contains n space-separated integers representing the temperatures for each hour.

outputFormat

The output should be printed to stdout and is a single integer representing the maximum sum of any continuous block of k hours.

## sample
8 3
1 3 -1 -3 5 3 6 7
16