Problems > Raise Everyone Up

Raise Everyone Up

Difficulty: 1100 3500 ms 128 MB

math

One move adds 1 to any single element. Print the minimum moves so all elements equal the (final) maximum — i.e. raise everything to the current maximum.

Input: the first line has N; the second line has N integers.

Output: ∑ (max − ai).

Constraints:

  • 1 ≤ N ≤ 105
  • |ai| ≤ 109

Sample Tests

Input 1
3
1 2 3
Output 1
3
Input 2
2
7 7
Output 2
0

Read the Editorial

Discussion (opens after you solve — no spoilers before)

No comments yet.

Submit Your Solution

Log in or create a free account to run and submit code.