错误点:long---TLE,long long---AC
思路:二分
#include<iostream> #include<cstring> #include<cstdio> #include<algorithm> using namespace std; typedef long long LL; LL cost[100005]; LL area[100005]; LL price[100005]; int main(){ int t; cin>>t; while(t--){ int n,m; scanf("%d%d",&n,&m); for(int i=0;i<n;++i){ scanf("%lld%lld",&area[i],&price[i]); cost[i]=area[i]*price[i]; } for(int i=n-2;i>=0;--i) cost[i]=min(cost[i],cost[i+1]); LL x; int l,r,mid; for(int i=0;i<m;++i){ scanf("%lld",&x); if(x>=area[n-1])printf("%lld\n",x*price[n-1]); else{ l=0,r=n-1; while(l<r){ mid=(l+r+1)>>1; if(area[mid]>x){ r=mid-1; } else l=mid; } printf("%lld\n",min(cost[l+1],price[l]*x)); } } } return 0; }