10611:Playboy Chimp

Problem Link

<Source Code>

#include<bits/stdc++.h>
#define pb push_back
#define sf(x) scanf(“%d”,&x)
#define MN 1234567
#define max 10000
#define all(water) (water.begin(),water.end());
#define fr(i,a,b) for(i=a;i<b;i++)
using namespace std;
#define cln(a) memset(a,0,sizeof(a))
#define ll long long
int main()
{int n,luchu;
while(cin>>n)
{
int lady[n],i,j,Q;
for(i=0;i<n;i++)
{
cin>>lady[i];
}
cin>>Q;
for(i=0;i<Q;i++)
{
cin>>luchu;
int low=(lower_bound(lady,lady+n,luchu)-lady-1);
int high=(upper_bound(lady,lady+n,luchu)-lady);

if(low>=0 &&low<n)
{
printf(“%d “,lady[low]);
}
else
printf(“X “);
if(high>=0 &&high<n)
printf(“%d\n”,lady[high]);
else printf(“X\n”);

}

}

return 0;
}

Advertisements

About waprogramming

I am in CSE,from CUET
This entry was posted in Uncategorized, uva and tagged , , , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s