原题链接:http://codeforces.com/contest/1041/problem/A
CF1041A Heist
There was an electronic store heist last night.
All keyboards which were in the store yesterday were numbered in ascending order from some integer number
. For example, if
and there were
keyboards in the store, then the devices had indices
and
, and if
and there were
of them then the keyboards had indices
and
.
After the heist, only keyboards remain, and they have indices . Calculate the minimum possible number of keyboards that have been stolen. The staff remember neither nor the number of keyboards in the store before the heist.
Input
The first line contains single integer — the number of keyboards in the store that remained after the heist.
The second line contains distinct integers — the indices of the remaining keyboards. The integers are given in arbitrary order and are pairwise distinct.
Output
Print the minimum possible number of keyboards that have been stolen if the staff remember neither nor the number of keyboards in the store before the heist.
Examples
input
4
10 13 12 8
output
2
input
5
7 5 6 4 8
output
0
Note
In the first example, if then minimum number of stolen keyboards is equal to . The keyboards with indices and were stolen during the heist.
In the second example, if then nothing was stolen during the heist.
题解
排序强校表示,排一遍序就能A (其实不用)。
代码
#include<bits/stdc++.h>
using namespace std;
int a[105],n;
void in(){scanf("%d",&n);for(int i=1;i<=n;++i)scanf("%d",&a[i]);}
void ac(){sort(a+1,a+1+n);printf("%d",a[n]-a[1]+1-n);}
int main(){in();ac();}