Sorted Arrays
Practice
3.5 (19 votes)
Arrays
Basic programming
Easy
Open
Problem
86% Success 10173 Attempts 20 Points 1s Time Limit 256MB Memory 1024 KB Max Code
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
- \(1 \le N \le 10^5\)
- \(1 \le a_i \le 10^6\)
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.
Submissions
Please login to view your submissions
Similar Problems
Points:20
264 votes
Tags:
ApprovedBasic ProgrammingEasyOpen
Points:20
76 votes
Tags:
Ad-HocBasic ProgrammingEasyOpen
Points:20
48 votes
Tags:
ApprovedBasic ProgrammingEasyImplementationOpen
Editorial