Advertisement
Egor_1425

Untitled

May 30th, 2024
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.48 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4.  
  5. using namespace std;
  6.  
  7. int main()
  8. {
  9.     int s, n;
  10.     cin >> s >> n;
  11.     vector <int> a(n);
  12.     for(int i = 0; i < n; i++)
  13.         cin >> a[i];
  14.     sort(a.begin(), a.end());
  15.     int prev_s = 0, count = 0;
  16.     for(int i = 0; i < n; i++)
  17.         if(a[i] >= s)
  18.         {
  19.             prev_s = a[i];
  20.             count++;
  21.             for(int j = i; j < n; j++)
  22.                 if(a[j] - prev_s >= 3)
  23.                 {
  24.                     count++;
  25.                     prev_s = a[j];
  26.                 }
  27.             break;
  28.         }
  29.     cout << count;
  30.     return 0;
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement