No.1416 Shopping Mall
タグ : / 解いたユーザー数 252
作問者 :
harurun
/ テスター :
Problem Statement
Oliver, who is British, is planning to build a shopping mall.
On floor $k\ (k \geq 0)$ of this shopping mall, there is space for at most $2^k$ shops.
Now, $n$ shops are going to move into this shopping mall, and $A_i$ staff members will come to the $i\ (1 \leq i \leq n)$-th shop.
Here, the cost of each shop is defined as follows.
- When the $i$-th shop is on floor $F_i\ (F_i \geq 0)$, its cost $C_i$ is $A_i \times F_i$
Oliver places the shops so that the total cost of all shops $\displaystyle \sum_{i=1}^{n} C_i$ is minimized.
Find the minimum value of this total cost.Note that the floor numbering does not start from floor $1$.
Input
$n$ $A_1\ A_2\ \ldots \ A_n$
The first line contains the number of shops $n$.
The second line contains $A_1,\ A_2,\ \cdots ,\ A_n$ separated by spaces.
Constraints
- All inputs are integers
- $1 \leq n \leq 5 \times 10^4$
- $1 \leq A_i \leq 10^3$
Output
Output the minimum value of the total cost.
Print a newline at the end.
Sample
Sample 1
Input
3 1 2 3
Output
3
Place the shop with $3$ staff members on floor $0$, and the shops with $1$ and $2$ staff members on floor $1$.
Thus, the desired value is $(3 \times 0) + (1 \times 1) + (2 \times 1) = 3$.
Sample 2
Input
1 1
Output
0
Sample 3
Input
15 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000
Output
34000
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。