We are given $$N$$ numbers. We have to select $$K$$ of them. We also have a number $$M$$. Suppose the numbers we selected were $$A_1, A_2 , A_3 .. A_k$$. (note that we write these numbers in order in which they appeared in the original array). Define $$ S = \sum_{i = 1}^{k}{A_i \cdot (i \mod M) } $$.
We have to maximize $$ S $$.
Constraints :
$$ N \leq 10^4 $$
$$ K \leq 10^3 $$
$$ | A_i | \leq 10^7 $$
$$ M \leq 10^7 $$
Input Format :
In the first line, three space separated integers $$N,K,M$$ are given. In the next line, $$N$$ space separated integers $$A_1,A_2,A_3, \dots A_n$$ are given.
Output Format :
Print a single integer corresponding to the answer.
Please login to use the editor
You need to be logged in to access the code editor
Loading...
Please wait while we load the editor
Login to unlock the editorial