情况如标题所示:
#include<bits/stdc++.h>
using namespace std;
const int MAXN=2e3+5;
bool t[MAXN];
int len[MAXN];
int give,cow,shed,res;
int main(){
cin>>give>>shed>>cow;
int start;cin>>start;
t[start]=1;
for(int i=2;i<=cow;i++){
int num;cin>>num;t[num]=1;
}
if(give>=cow) {cout<<cow;return 0;}
int cnt=0,num=0;bool q=0;
for(int i=start;i<=shed;i++){
if(t[i]==0) cnt++;
if(t[i]==1) {
len[num++]=cnt;
cnt=0;
}
}
cout<<endl;
sort(len+1,len+1+num);
int need=cow,list=0,wood=cow;
while(need>=give-1){
need--;
wood+=len[list++];
}
cout<<wood;
return 0;
}
附测试点1
in:
4 50 17
3
4
6
8
14
15
16
17
25
26
27
30
31
40
41
42
43
ans:21