Advertisement
Josif_tepe

Untitled

Dec 28th, 2021
1,143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.60 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4. #include <cstring>
  5. using namespace  std;
  6. int main() {
  7.     int visina, n;
  8.     cin >> visina >> n;
  9.     vector<int> v(n);
  10.    
  11.     for(int i = 0; i < n; i++) {
  12.         cin >> v[i];
  13.     }
  14.     visina += 5;
  15.     int L = 0;
  16.     int R = n - 1;
  17.    
  18.     while(L < R) {
  19.         int middle = L + (R - L) / 2;
  20.         if(visina <= v[middle]) {
  21.             R = middle;
  22.         }
  23.         else {
  24.             L = middle + 1;
  25.         }
  26.     }
  27.     if(L < n and v[L] < visina) {
  28.         L++;
  29.     }
  30.     cout << L << endl;
  31.     return 0;
  32. }
  33.  
  34.  
  35.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement