分析:我们不断统计相邻两个元素之间的差值,按照差值从大到小排序,在进行贪心即可
/*
PROB:barn1
ID:wanghan
LANG:C++
*/
#include "iostream"
#include "cstdio"
#include "cstring"
#include "string"
#include "cmath"
#include "algorithm"
using namespace std;
const int maxn=;
int m,s,c;
int stall[maxn];
struct Node
{
int sub,id;
};
Node p[maxn];
bool cmp(Node x,Node y){
return x.sub>y.sub;
}
int vis[maxn];
int main()
{
freopen("barn1.in", "r", stdin);
freopen("barn1.out", "w", stdout);
cin>>m>>s>>c;
for(int i=;i<c;i++){
cin>>stall[i];
}
sort(stall,stall+c);
for(int i=;i<c;i++){
p[i].id=i;
p[i].sub=stall[i]-stall[i-];
}
//p[c].id=c;
//p[c].sub=s-stall[c-1];
sort(p+,p+c,cmp);
if(m>=c){
cout<<c<<endl;
}else{
int cnt=stall[c-]-stall[];
//cout<<cnt<<endl;
for(int i=;i<m;i++){
cnt-=p[i].sub;
//cout<<"sub:"<<p[i].sub<<endl;
//cout<<cnt<<endl;
}
cout<<cnt+m<<endl;
}
}