fork download
  1. #include<bits/stdc++.h>
  2. #define ll long long
  3. #define mp make_pair
  4. #define f(i,n) for(int i=0;i<n;i++)
  5. #define F first
  6. #define S second
  7. #define pb push_back
  8.  
  9. using namespace std;
  10.  
  11. void test(){
  12. ll n,m;
  13. cin>>n>>m;
  14.  
  15. if(m==0){
  16. cout<<"1\n";
  17. return ;
  18. }
  19.  
  20. vector<ll> a(m);
  21. f(i,m)cin>>a[i];
  22. sort(a.begin(),a.end());
  23. if(a[m-1]!=n)a.pb(n+1);
  24. if(a[0]!=1)a.pb(0);
  25. sort(a.begin(),a.end());
  26.  
  27. vector<ll> v;
  28.  
  29. f(i,a.size()-1){
  30. if(a[i+1]-a[i]-1!=0)
  31. v.pb(a[i+1]-a[i]-1);
  32. }
  33. if(v.size()==0){
  34. cout<<"0\n";
  35. return ;
  36. }
  37. sort(v.begin(),v.end());
  38.  
  39. ll dif = v[0];
  40. ll res = 0;
  41. f(i,v.size()){
  42. res = res + (v[i]/dif);
  43. if(v[i]%dif!=0)res++;
  44. }
  45. cout<<res<<"\n";
  46.  
  47. }
  48.  
  49. int main(){
  50. std::ios::sync_with_stdio(false);
  51. cin.tie(0);
  52. cout.tie(0);
  53. int tests=1;
  54. // cin>>tests;
  55. while(tests--){
  56. test();
  57. }
  58. }
  59.  
Success #stdin #stdout 0s 5008KB
stdin
5 2
1 3
stdout
3