Advertisement
Falak_Ahmed_Shakib

upper bound own

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