本来是水题一道,妈蛋inf开太小了,这题又都要用I64d,搞得wa了好多次
#include <iostream>
#include <cstring>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <queue>
#include <map>
using namespace std;
#define INF 1e13
#define maxn 100010
#define rep(i,x,y) for(int i=x;i<=y;i++)
#define mset(x) memset(x,0,sizeof(x))
typedef __int64 ll;
int kase;
ll s[maxn], p[maxn], minsp[maxn], q;
int n, m;
int main(){
// freopen("a.txt","r",stdin);
// freopen(".out","w",stdout);
cin>>kase;
while(kase--){
cin>>n>>m;
rep(i,1,n) scanf("%I64d%I64d", &s[i], &p[i]);
minsp[n+1] = INF;
for(int i=n; i>=1; i--) minsp[i] = min(minsp[i+1], s[i]*p[i]);
rep(i,1,m){
scanf("%I64d", &q);
int pos = lower_bound(s+1, s+1+n, q) - s;
//printf("%I64d %d\n", q, pos);
ll ans;
if(pos>1) pos--;
ans = min(p[pos]*q, minsp[pos+1]);
printf("%I64d\n", ans);
}
}
return 0;
}