#P15859. [蓝桥杯第二届国际赛] 模糊滤镜

[蓝桥杯第二届国际赛] 模糊滤镜

Background

It is uncertain whether this problem is included in the Lanqiao Cup 2nd International Contest. The official Lanqiao Cup statement crossed out the problem number, but the problem itself is still kept.

Problem Description

For an ordered signal s1,s2,…,sns_1, s_2, \ldots, s_n, each number in the signal is a positive integer. When applying a blur filter to this signal, a new signal t1,t2,…,tnt_1, t_2, \ldots, t_n is obtained. The values of the new signal are defined as t1=⌊(s1+s2)/2⌋t_1 = \lfloor (s_1+s_2)/2 \rfloor, t2=⌊(s1+s2+s3)/3⌋t_2 = \lfloor (s_1+s_2+s_3)/3 \rfloor, t3=⌊(s2+s3+s4)/3⌋t_3 = \lfloor (s_2+s_3+s_4)/3 \rfloor, …\ldots, tn−1=⌊(sn−2+sn−1+sn)/3⌋t_{n-1} = \lfloor (s_{n-2}+s_{n-1}+s_n)/3 \rfloor, tn=⌊(sn−1+sn)/2⌋t_n = \lfloor (s_{n-1}+s_n)/2 \rfloor, where ⌊x⌋\lfloor x \rfloor denotes the greatest integer not exceeding xx.

Now the blurred signal tt is given. Please compute the signal ss. If there are multiple valid ss, find the one with the smallest s1s_1. If there are multiple solutions with the same s1s_1, find the one with the smallest s2s_2, and so on. In other words, find the lexicographically smallest sequence s1,s2,s3,…,sns_1, s_2, s_3, \ldots, s_n.

Input Format

The first line contains an integer nn.

The second line contains nn integers, which are t1,t2,…,tnt_1, t_2, \ldots, t_n in order.

Output Format

Output one line containing nn integers, representing s1,s2,…,sns_1, s_2, \ldots, s_n in order. Note that every number in ss must be a positive integer.

5
1 2 3 4 5
1 1 4 4 6

Hint

Constraints

For 40%40\% of the test cases, 2≤n≤202 \le n \le 20, and each number in the signal tt is a positive integer not exceeding 100100.

For 60%60\% of the test cases, 2≤n≤3002 \le n \le 300, and each number in the signal tt is a positive integer not exceeding 100100.

For all test cases, 2≤n≤50002 \le n \le 5000, and each number in the signal tt is a positive integer not exceeding 10000001000000.

Please note that the above ranges apply to each number in the signal tt. Each number in the signal ss may exceed this range.

Translated by ChatGPT 5