#C6441. Maximum Consecutive Knights Strength
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:
- The first line contains an integer n which represents the number of knights.
- The second line contains n space-separated integers representing the strength values of the knights.
- 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.
## sample7
10 -5 -6 -2 14 6 -3
3
18