F - Heist

昨天滨院acm集训队遭到了很严重的盗窃,万恶的小偷将同学们梦寐以求的签到题偷走了。在失窃后,命题组手中还有n道签到题,编号分别为a1, a2, … an。现在命题组要统计有多少道试题失窃从而重新给同学们制作可爱的签到题。已知签到题从小到大编号,并且编号是连号的。换句话说,如果有两道签到题编号分别为4,9,则4-9内所有数字均为签到题编号。现在,由于命题人很懒,想要出尽可能少的题目,所以要求给出最少有多少道签到题失窃。

ps:这是一道没有被偷走的签到题奥

Input
The first line contains single integer n (1≤n≤1000) — the number of questoins in the store that remained after the heist. The second line contains n distinct integers a1,a2,…,an (1≤ai≤10^9) — the indices of the remaining questoins. The integers ai are given in arbitrary order and are pairwise distinct.

Output
Print the minimum possible number of questoins that have been stolen

Examples

Input
4
10 13 12 8

Output
2

Input
5
7 5 6 4 8

Output
0

Note
In the first example, if x=8 then minimum number of stolen questoins is equal to 2. The questoins with indices 9 and 11 were stolen during the heist. In the second example, if x=4 then nothing was stolen during the heist.

简单的快排,轻松解决问题

代码:

#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
    int n;
    cin>>n;
    int a[n];
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    sort(a,a+n);
    int num=0;
    for(int i=0;i<n-1;i++){
        num+=a[i+1]-a[i]-1;
    }
    cout<<num;
    return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值