天天看点

HDU 4791 Alice's Print Service (水)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4791

#include<bits/stdc++.h>
using namespace std;

#define debug puts("YES");
#define rep(x,y,z) for(int (x)=(y);(x)<(z);(x)++)
#define ll long long

#define lrt int l,int r,int rt
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define root l,r,rt
#define mst(a,b) memset((a),(b),sizeof(a))
const int  maxn =1e5+5;
const int mod=9999991;
const int ub=1e6;
ll powmod(ll x,ll y){ll t; for(t=1;y;y>>=1,x=x*x%mod) if(y&1) t=t*x%mod; return t;}
ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}

ll p[maxn],s[maxn];
ll n,m,x,dp[maxn];

int main(){
    int t;scanf("%d",&t);
    while(t--){
        scanf("%lld%lld",&n,&m);
        for(int i=1;i<=n;i++) scanf("%lld%lld",&s[i],&p[i]);
        dp[n+1]=1e18,dp[n]=s[n]*p[n];
        for(int i=n-1;i>=1;i--) dp[i]=min(dp[i+1],s[i]*p[i]);
        for(int i=1;i<=m;i++){
            scanf("%lld",&x);
            int pos=upper_bound(s+1,s+n+1,x)-s;
            printf("%lld\n",min(dp[pos],p[pos-1]*x));
        }
    }
    return 0;
}
           

继续阅读