| IX MaratonUSP Freshman Contest |
|---|
| Finished |
It is finally time for humanity to colonize Mercury. However, a major problem for creating cities on the closest planet to the Sun is its rugged terrain. For proper city construction, the terrain of the planet needs to be leveled.
Paulo is a flat-earther (i.e., someone who flattens the earth) from IME (International Mercury Excavation), hired to fix Mercury's terrain. Mercury's horizon consists of $$$n$$$ hills, each with a height $$$a_i$$$. Due to the quantum nature of Mercury's sand, it is not possible to move sand between hills, so Paulo can only reduce their height and never increase it.
Antônio, president of the ACM (Association for the Conservation of Mercury), is very concerned about the changes that will be made to the planet and would like the terrain to be altered as little as possible, that is, the total number of meters of sand removed should be minimized. Paulo, being a natural flat-earther, is not good at math and needs your help to calm Antônio. Help Paulo determine the minimum meters of sand that must be removed from Mercury's hills so that the terrain is uniform.
The input consists of two lines.
The first line contains a single positive integer $$$n\ (1 \leq n \leq 10^5)$$$ — the number of hill in Mercury's horizon.
The second line contains $$$n$$$ numbers $$$a_i\ (1 \leq a_i \leq 10^4)$$$ — the heights in meters of wach hill.
Print a single non-negative integer, the minimum number of meters Paulo must dig so that Mercury's horizon becomes uniform.
24 10
6
45 15 13 27
40
63 4 3 5 7 6
10
| Name |
|---|


