当前位置: 代码迷 >> 综合 >> ZOJ 3726 Alice's Print Service (水题)
  详细解决方案

ZOJ 3726 Alice's Print Service (水题)

热度:47   发布时间:2023-11-15 15:10:16.0

题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3726

#include<bits/stdc++.h>
using namespace std;#define debug puts("YES");
#define rep(x,y,z) for(int (x)=(y);(x)<(z);(x)++)
#define read(x,y) scanf("%d%d",&x,&y)
#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
const int  maxn =1e5+5;
const int mod=1e9+7;
const ll INF =1e18+7;
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 n,m,q;
ll s[maxn],p[maxn];
ll bit[maxn];int main()
{int t;scanf("%d",&t);while(t--){scanf("%lld%lld",&n,&m);for(int i=0;i<n;i++) scanf("%lld%lld",&s[i],&p[i]);bit[n]=INF;for(int i=n-1;i>=0;i--) bit[i]=min(bit[i+1],s[i]*p[i]);for(int i=0;i<m;i++){scanf("%lld",&q);int pos=upper_bound(s,s+n,q)-s;ll ans=bit[pos]; ans=min(ans,1LL*q*p[pos-1]);printf("%lld\n",ans);}}return 0;
}

 

  相关解决方案