直接找出最长的m-1个没牛的地方
然后直接减,再把头尾一去不就好了
我也不知道为啥WA了2个。。。。
#include <iostream>
#include <algorithm>
using namespace std;
bool cmp(int a,int b){
return a>b;
}
int cow[202],ge[202];
int main(){
int m,s,c;
cin >> m >> s >> c;
for(int i = 0;i < c;i++){
cin >> cow[i];
}
sort(cow,cow+c);
for(int i = 0;i < c - 1;i++){
ge[i] = cow[i + 1] - cow[i];
}
sort(ge,ge+c,cmp);
int ans = cow[c - 1] - (cow[0] - 1);
for(int i = 0;i < m - 1;i++){
ans-=ge[i];
ans++;
}
cout << ans << endl;
return 0;
}