Loading...
Loading...
The online store writes down its sales in rupees for n days. The manager wants a smooth trend, so for every block of k consecutive days she needs the average sale.
Print the average of every block of k consecutive days, from the first block to the last. Round each average down to a whole number.
Example 1
Input
5 3 120 80 100 90 200
Output
100 90 130
The totals are 300, 270 and 390, so the averages are 100, 90 and 130.
Example 2
Input
4 2 5 6 7 8
Output
5 6 7
The totals are 11, 13 and 15. 11 / 2 = 5.5 is rounded down to 5.
Try the problem first. Open one hint at a time.
Two neighbouring blocks share k − 1 days. Only one day leaves and one day joins.
Find the total of the first k days. For each next block, add the new day and subtract the day that left.
Print total / k for each block. Sales are never negative, so whole-number division already rounds down.
A total can reach 10^5 × 10^9 = 10^14, so keep it in a long.
Write your Java code, run it on the examples and submit it to hidden tests.
Solve in the editor