#C6441. Maximum Consecutive Knights Strength

    ID: 50202 Type: Default 1000ms 256MiB

Maximum Consecutive Knights Strength

Maximum Consecutive Knights Strength

You are given n knights arranged in a circle. Each knight has a strength value. Your task is to find the maximum sum of strengths for any group of k consecutive knights. In other words, if the strengths of the knights are represented as a sequence \(a_1, a_2, \dots, a_n\), then you need to compute:

\(\max_{0 \leq i < n}\left(\sum_{j=0}^{k-1} a_{(i+j) \bmod n}\right)\)

Note that if \(k=0\), the answer is defined to be 0.

Input/Output instructions follow standard input (stdin) and standard output (stdout) conventions.

inputFormat

The input consists of three lines:

  1. The first line contains an integer n which represents the number of knights.
  2. The second line contains n space-separated integers representing the strength values of the knights.
  3. The third line contains an integer k representing the number of consecutive knights to choose.

Note: The knights are arranged in a circle, so the sequence is circular.

outputFormat

Output a single integer, the maximum sum of strengths of any k consecutive knights.

## sample
7
10 -5 -6 -2 14 6 -3
3
18