提交时间:2023-12-01 13:31:14

运行 ID: 113125

#include <bits/stdc++.h> using namespace std; const int N=20000+10; const int INF=0x3f3f3f3f; int m,s,c,a[N],jian_ge[N]; int cmp(int x,int y) { return x>y; } int main() { cin>>m>>s>>c; for(int i=1;i<=c;i++) { cin>>a[i]; } sort(a+1,a+c+1); for(int i=1;i<=c-1;i++) { jian_ge[i]=a[i+1]-a[i]-1; } sort(jian_ge+1,jian_ge+c,cmp); int maxx=a[c]-a[1]+1; for(int i=1;i<=m-1;i++) { maxx-=jian_ge[i]; } cout<<maxx; return 0; }