問題一覧 > 通常問題

No.1416 Shopping Mall

レベル : / AI推定難易度 : 400 / 実行時間制限 : 1ケース 1.000秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (解説公開後に AC するまで非表示) / 解いたユーザー数 252
作問者 : harurun / テスター : NatsubiSogan
お気に入りにしたユーザー ProblemId : 5664 / 自分の提出
問題文最終更新日: 2021-02-18 11:02:59
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence. Back to the original
yukicoder contest 285 (順位表) の他の問題:

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もしくは右上の雲マークをクリックしてアカウントを作成してください。