Advertisement
Falak_Ahmed_Shakib

Untitled

Nov 26th, 2019
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.96 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. typedef long long ll;
  4. #define fastread() (ios_base:: sync_with_stdio(false),cin.tie(NULL))
  5. #define fi first
  6. #define se second
  7. #define pb push_back
  8. #define eb emplace_back
  9.  
  10. vector<ll>v;
  11.  
  12. ll lower(ll key)
  13. {
  14.  
  15.  
  16. ll pos;
  17.  
  18.  
  19.  
  20.  
  21. ll s=0;
  22. ll e=v.size()-1;
  23. ll mid=(s+e)/2;
  24.  
  25. while(s<=e)
  26. { mid=(s+e)/2;
  27. // cout<<mid<<endl;
  28. // cout<<s<<" "<<e<<endl; the way ;;
  29.  
  30. if(v[mid]>=key)
  31. {
  32. e=mid-1;
  33. pos=mid;
  34.  
  35. }
  36. else
  37. {
  38. s=mid+1;
  39. }
  40.  
  41.  
  42.  
  43. }
  44.  
  45. return pos;
  46.  
  47. }
  48.  
  49.  
  50. #define eb emplace_back
  51. int main()
  52. {
  53. fastread();
  54. ll n;
  55. cin>>n;
  56.  
  57.  
  58.  
  59.  
  60.  
  61.  
  62. for(ll i=0;i<n;i++)
  63. {
  64. ll a;
  65. cin>>a;
  66.  
  67. v.pb(a);
  68. }
  69.  
  70.  
  71. sort(v.begin(),v.end());
  72.  
  73. ll key;
  74.  
  75. cin>>key;
  76.  
  77. ll pos=lower(key);
  78.  
  79. cout<<pos<<endl;
  80.  
  81.  
  82. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement