You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
29 lines
625 B
C++
29 lines
625 B
C++
#include <cstdio>
|
|
#include <algorithm>
|
|
using namespace std;
|
|
typedef long long ll;
|
|
const int N=1e5+10;
|
|
ll x[N],y[N],s[N];
|
|
int main()
|
|
{
|
|
int T,n,m;
|
|
scanf("%d",&T);
|
|
while(T--)
|
|
{
|
|
scanf("%d%d",&n,&m);
|
|
for(int i=0; i<n; i++)
|
|
scanf("%lld%lld",x+i,y+i),s[i]=x[i]*y[i];
|
|
s[n]=1e16;
|
|
for(int i=n; i; i--)
|
|
s[i-1]=min(s[i-1],s[i]);
|
|
while(m--)
|
|
{
|
|
ll q;
|
|
scanf("%lld",&q);
|
|
int pos=lower_bound(x,x+n,q)-x-1;
|
|
printf("%lld\n",min(y[pos]*q,s[pos+1]));
|
|
}
|
|
}
|
|
return 0;
|
|
}
|