Sorted Arrays

3.5

19 votes
Arrays, Basic Programming, Easy, Open
Problem

Alice has recently found an array a containing N integers. As we all know Alice loves sorted array so, he wants to sort the array. To sort an array Alice can add 1 to any integer in the array in 1 move.

Alice wants to find minimum number of moves needed to sort this array. Remember that after sorting the array, all elements in it should be distinct.

INPUT CONSTRAINTS

  • 1N105
  • 1ai106

INPUT FORMAT
First line of input contains a single integer N.
Second line of input contains N space separated inegers, elements of array a.

OUTPUT FORMAT
Output a single integer, denoting number of moves needed to sort the given array.

Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation

In first move Alice will add 1 to third integer then, in second move Alice will do the same he did in 1st move.

Editor Image

?