No.952 Dangerous Powder Magazine
Problem Statement
There is a powder magazine with $N$ doors, numbered $1,\ 2,\ \dots,\ N$ from left to right.
Each door $i$ has a fixed danger level $A_i$ that applies when the door is open. Currently, all doors are closed.
You are going to open some of the doors for ventilation.
The danger level of the powder magazine when some doors are open is defined as follows.
For each $k = 1,\ 2,\ ...,\ N$, find the minimum danger level of the powder magazine when $k$ doors to open are chosen appropriately.
Constraints
Input
$N$ $A_1\ A_2\ \dots \ A_N$
$N$ is the number of doors.
$A_i$ is the danger level of door $i$ when it is open.
Output
On line $k\ (1\le k\le N)$, print the minimum danger level of the powder magazine when $k$ doors to open are chosen appropriately.
Print a newline at the end.
Sample
Sample 1
Input
5 1 2 3 4 5
Output
1 9 25 61 225
| Number of doors to open $\qquad$ | Doors to open $\qquad$ | Minimum danger level of the powder magazine $\qquad$ |
|---|---|---|
| $1$ | $1$ | $1^2=1$ |
| $2$ | $1,\ 2$ | $(1+2)^2=9$ |
| $3$ | $1,\ 2,\ 4$ | $(1+2)^2+4^2=25$ |
| $4$ | $1,\ 2,\ 3,\ 5$ | $(1+2+3)^2+5^2=61$ |
| $5$ | $1,\ 2,\ 3,\ 4,\ 5$ | $(1+2+3+4+5)^2=225$ |
Sample 2
Input
7 10000 10001 10002 10003 10001 10000 10002
Output
100000000 200000000 300040004 400100009 900180014 1800360018 4901260081
Sample 4
Input
10 1 2 3 4 5 6 7 8 9 10
Output
1 9 25 61 110 191 300 550 1145 3025
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。
tatyam