还是水题一个,对两个有牛的牛棚之间进行贪心,然后对长度为S的木板递减,直到M用光或者没有间距;
code
/*
ID: yueqiq
PROG: barn1
LANG: C++
*/
#include <set>
#include <map>
#include <ctime>
#include <queue>
#include <cmath>
#include <stack>
#include <limits>
#include <vector>
#include <bitset>
#include <string>
#include <cstdio>
#include <cstring>
#include <fstream>
#include <string.h>
#include <iostream>
#include <algorithm>
#define Si set<int>
#define LL long long
#define pb push_back
#define PS printf(" ")
#define Vi vector<int>
#define LN printf("\n")
#define lson l,m,rt << 1
#define rson m+1,r,rt<<1|1
#define SD(a) scanf("%d",&a)
#define PD(a) printf("%d",a)
#define SET(a,b) memset(a,b,sizeof(a))
#define FF(i,a) for(int i(0);i<(a);i++)
#define FD(i,a) for(int i(a);i>=(1);i--)
#define FOR(i,a,b) for(int i(a);i<=(b);i++)
#define FOD(i,a,b) for(int i(a);i>=(b);i--)
#define readf freopen("barn1.in","r",stdin)
#define writef freopen("barn1.out","w",stdout)
const int maxn = 201;
const int INF = 0x3fffffff;
const int dx[]={0,1,0,-1};
const int dy[]={1,0,-1,0};
const double pi = acos(-1.0);
using namespace std;
int M,S,C;
bool use[maxn];
int dis[maxn];
int main(){
readf;
writef;
scanf("%d%d%d",&M,&S,&C);
int mm=INF,mx=0;
FOR(i,1,C){
int k;SD(k);
if(k<mm) mm=k;
if(k>mx) mx=k;
use[k]=true;
}
int tmp=mm;
int cnt=0;
FOR(i,mm+1,mx){
if(use[i]){
dis[cnt++]=(i-tmp-1);
tmp=i;
}
}
// FOR(i,0,cnt){
// PD(dis[i]);LN;
// }
sort(dis,dis+cnt+1);
int count=1;
int mdis=S-(mm-1)-(S-mx);
// PD(mdis);LN;
while(count<M){
mdis-=dis[cnt];
count++;
cnt--;
if(cnt<0) break;
}
PD(mdis);LN;
return 0;
}