#K4546. Maximizing Consecutive Bench Sum in a Circular Arrangement
Maximizing Consecutive Bench Sum in a Circular Arrangement
Maximizing Consecutive Bench Sum in a Circular Arrangement
You are given N benches arranged in a circle, numbered from 1 to N. Each bench is labeled with its number. For a given positive integer K (with K ≤ N), your task is to find the starting bench number such that the sum of K consecutive benches (in circular order) is maximized. In other words, if you consider a window of K benches starting at bench i and wrapping around if necessary, you need to choose the smallest i that gives the highest possible sum.
More formally, if we denote the bench labels by a_i = i for i = 1, 2, ..., N, then for a starting bench i, the sum is given by $$S(i) = \sum_{j=0}^{K-1} a_{((i-1+j) \mod N) + 1}. $$
You are required to output the starting bench number i for which S(i) is maximized. If there are multiple such i, output the smallest one.
inputFormat
The input consists of a single line with two space-separated integers: N
and K
.
N
— the total number of benches.K
— the number of consecutive benches to consider.
outputFormat
Output a single integer, which is the starting bench number that maximizes the sum of K
consecutive benches when arranged in a circle.
8 3
6