Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cmath>
- #include <cstdio>
- #include <vector>
- #include <iostream>
- #include <algorithm>
- using namespace std;
- #define ll long long
- bool P(ll a, ll key ){
- return a >= key ;
- }
- int lower_b(ll * a, int last_index , ll key , int l , int h ){
- if ( l>=h ){
- if ( P(a[l],key)== false ) return last_index+1;
- return l;
- }
- else {
- int mid = l+(h-l)/2;
- if ( P(a[mid],key) ){
- h=mid;
- }
- else {
- l=mid+1;
- }
- return lower_b(a,last_index,key, l, h);
- }
- }
- int main() {
- int n;
- cin >> n;
- ll * a= new ll [n];
- for (int i=0;i<n;i++) cin >> a[i];
- ll key;
- cin >> key ;
- cout<<lower_b(a,n-1,key,0,n-1);
- /* Enter your code here. Read input from STDIN. Print output to STDOUT */
- return 0;
- }
Add Comment
Please, Sign In to add comment