您的位置:首页 > 其它

UVALive 6611 Alice's Print Service(二分)

2016-07-30 23:12 274 查看
思路:二分二分就好了

#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <cstdlib>
#include <ctime>

#define INF 0x3f3f3f3f
#define esp 1e-9
typedef long long LL;
using namespace std;
const int N=1e5+10;
int n,m,T,a
,b
;
struct node
{
LL v;
int i;
bool operator < (const node&a)const
{
return v<a.v;
}
};
node s
;
int main()
{
//freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout);
scanf("%d",&T);
while(T--)
{
scanf("%d%d",&n,&m);
for(int i=0;i<n;i++) scanf("%d%d",a+i,b+i);
a
=2*1e9;
b
=2*1e9;
int k=0;
s[0].v=(LL)a
*b
;
s[0].i=n;
for(int i=n-1;i>=0;i--)
{
if((LL)a[i]*b[i]<s[k].v)
{
s[++k].v=(LL)a[i]*b[i];
s[k].i=i;
}
}
k++;
sort(s,s+k);
while(m--)
{
int x;
scanf("%d",&x);
int y=upper_bound(a,a+n+1,x)-a-1;
LL ans=(LL)x*b[y];
int z=upper_bound(s,s+k,node{ans,0})-s-1;
if(s[z].i>y) ans=s[z].v;
printf("%lld\n",ans);
}
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: