#K57757. Revenue Sequence Modification

    ID: 30491 Type: Default 1000ms 256MiB

Revenue Sequence Modification

Revenue Sequence Modification

You are given an integer n representing the number of days and a sequence of n integers representing daily revenues. The company policy requires you to update the revenue sequence using the following rule:

For each day i (0-indexed), compute the running total T including the revenue of day i as:

[ T = \sum_{j=0}^{i} r_j ]

and the average revenue up to that day is:

[ average = \frac{T}{i+1} ]

If the revenue ri is strictly less than the current average, set that day’s revenue to 0 and subtract its value from the running total; otherwise, keep the revenue unchanged. Output the modified sequence.

Note: All calculations are performed in a sequential manner; once a value is modified to 0, it does not contribute to the average for subsequent days.

inputFormat

The input is given via stdin and consists of two lines:

  • The first line contains a single integer n (1 ≤ n ≤ 105) which is the number of days.
  • The second line contains n space-separated integers representing the daily revenues.

outputFormat

The output should be printed to stdout as a single line of n space-separated integers, representing the modified revenue sequence after applying the company policy.

## sample
5
10 20 30 40 50
10 20 30 40 50

</p>