Editorial for COCI '14 Contest 1 #1 Prosjek


Remember to use this editorial only when stuck, and not to copy-paste code from it. Please be respectful to the problem author and editorialist.
Submitting an official solution before solving the problem yourself is a bannable offence.

Let S_k be the sum of the first k numbers in sequence A. It holds:

\displaystyle B_k = \frac{S_k}{k}

It follows:

\displaystyle B_{k+1} = \frac{S_k+A_{k+1}}{k+1}

From here we get the expression for A_{k+1}:

\displaystyle A_{k+1} = (k+1)B_{k+1}-S_k

We calculate elements of the sequence A_{k+1} and their sum S_k iteratively by using one loop over sequence B.


Comments

There are no comments at the moment.