题目链接:
http://codeforces.com/problemset/problem/706/B
题目大意:
n (1 ≤ n ≤ 100 000)个商店卖一个东西,每个商店的价格Ai,你有m(1≤m≤100 000)天,每天有Cj的钱,问每天可以负的起的商店数。
题目思路:
【二分】
排个序,二分。
//
//by coolxxx
//
#include<iostream>
#include<algorithm>
#include<string>
#include<iomanip>
#include<memory.h>
#include<time.h>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
//#include<stdbool.h>
#include<math.h>
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define abs(a) ((a)>0?(a):(-(a)))
#define lowbit(a) (a&(-a))
#define sqr(a) ((a)*(a))
#define swap(a,b) ((a)^=(b),(b)^=(a),(a)^=(b))
#define eps (1e-8)
#define J 10000000
#define MAX 0x7f7f7f7f
#define PI 3.1415926535897
#define N 100004
using namespace std;
typedef long long LL;
int cas,cass;
int n,m,lll,ans;
int a[N];
bool cmp(int aa,int bb)
{
return aa<bb;
}
int work(int v)
{
int l=0,r=n,mid;
while(l<r)
{
mid=(l+r+1)>>1;
if(v>=a[mid])l=mid;
else r=mid-1;
}
return r;
}
int main()
{
#ifndef ONLINE_JUDGE
// freopen("1.txt","r",stdin);
// freopen("2.txt","w",stdout);
#endif
int i,j,x,v;
// for(scanf("%d",&cas);cas;cas--)
// for(scanf("%d",&cas),cass=1;cass<=cas;cass++)
// while(~scanf("%s",s))
while(~scanf("%d",&n))
{
for(i=1,x=0;i<=n;i++)
{
scanf("%d",&a[i]);
x=max(a[i],x);
}
sort(a+1,a+1+n,cmp);
scanf("%d",&m);
for(i=1;i<=m;i++)
{
scanf("%d",&v);
if(v>=x)printf("%d\n",n);
else printf("%d\n",work(v));
}
}
return 0;
}
/*
//
//
*/