No.8044 April Sum of Odd
Problem Statement
Integers $N,M$ and an integer sequence of length $N$ are given, separated by spaces. The elements are $A_1 A_2 \dots A_N$.
For each of all the segments of this sequence in which M or more odd numbers appear consecutively, output the sum of its elements.
It is guaranteed that there is at least one answer to output.
Input
$N M$ $A_1 A_2 \dots A_N$
$1 \le N \le 10$$5$
$1 \le M \le N$
$0 \le A_i \le 10$$9$
Output
$S_1$ $S_2$ $\dots$ $S_T$
The output consists of T lines.
Here, T is the number of segments in which M or more odd numbers appear consecutively.
For the T segments, output the sum of each, separated by newlines.
Sample
Sample 1
Input
5 3 2 1 3 5 4
Output
9
The only place where three or more odd numbers appear consecutively is {1,3,5}, and its sum is 9.
Sample 2
Input
6 2 1 3 2 4 5 7
Output
4 12
Two or more odd numbers appear consecutively in the two places {1,3} {5,7}, so output their respective sums 4,12 in this order.
Sample 3
Input
10 1 1000000000 99999999 99999998 99999999 99999999 99999999 2 786567 564391 6547849
Output
99999999 299999997 7898807
{99999999}
{99999999 99999999 99999999}
{786567 564391 6547849}
Output for these three segments in this order.
Note that the values may not fit in a 32-bit integer.
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。
gotutiyan