#include<bits/stdc++.h>
using namespace std;
#define fr(i,x) for(i=0;i<x;i++)
int binaryupper(int a[],int m,int l,int u)
{
int mid,c=0;
if(l<=u)
{
mid=(l+u)/2;
if(m==a[mid])
{
c=m;
return binaryupper(a,m,mid+1,u);
}
else if(m<a[mid])
{
return binaryupper(a,m,l,mid-1);
}
else
{
return binaryupper(a,m,mid+1,u);
}
}
else
return u;
}
int main()
{
int n;
while(cin>>n)
{
int ar[100010]= {0},i,a;
fr(i,n)
{
cin>>ar[i];
}
cin>>a;
cout<<binaryupper(ar,a,0,n-1)<<endl;
}
}
using namespace std;
#define fr(i,x) for(i=0;i<x;i++)
int binaryupper(int a[],int m,int l,int u)
{
int mid,c=0;
if(l<=u)
{
mid=(l+u)/2;
if(m==a[mid])
{
c=m;
return binaryupper(a,m,mid+1,u);
}
else if(m<a[mid])
{
return binaryupper(a,m,l,mid-1);
}
else
{
return binaryupper(a,m,mid+1,u);
}
}
else
return u;
}
int main()
{
int n;
while(cin>>n)
{
int ar[100010]= {0},i,a;
fr(i,n)
{
cin>>ar[i];
}
cin>>a;
cout<<binaryupper(ar,a,0,n-1)<<endl;
}
}
কোন মন্তব্য নেই:
একটি মন্তব্য পোস্ট করুন