#P15755. [JAG 2025 Summer Camp #1] JAG Box

[JAG 2025 Summer Camp #1] JAG Box

题目描述

The JAG Box is an ordinary rectangular box that is currently popular around the world. There are NN JAG Boxes. For each i=1,2,,Ni = 1, 2, \ldots, N, the ii-th box has an integer weight AiA_i.

You will build a vertical stack by repeatedly choosing one remaining box and inserting it at the very bottom of the current stack. When a box of weight ww is inserted at the bottom of the existing stack whose total weight is xx, that box receives load equal to xw\left\lfloor \frac{x}{w} \right\rfloor.

Determine the minimum possible total load over all boxes.

输入格式

The input is given in the following format:

$$\begin{aligned} &N \\ &A_1 \ A_2 \ \ldots \ A_N \end{aligned} $$
  • 2N2000002 \leq N \leq 200\,000
  • 1Ai1091 \leq A_i \leq 10^9 (1iN1 \leq i \leq N)
  • All input values are integers.

输出格式

Output the answer in a single line.

5
3 1 4 1 5
3