Alice's Print Service


Time Limit: 2 Seconds      Memory Limit: 65536 KB

Alice is providing print service, while the pricing doesn't seem to be reasonable, so people using her print service found some tricks to save money.

For example, the price when printing less than 100 pages is 20 cents per page, but when printing not less than 100 pages, you just need to pay only 10 cents per page. It's easy to figure out that if you want to print 99 pages, the best choice is to print an extra blank page so that the money you need to pay is 100 × 10 cents instead of 99 × 20 cents.

Now given the description of pricing strategy and some queries, your task is to figure out the best ways to complete those queries in order to save money.

Input

The first line contains an integer T (≈ 10) which is the number of test cases. Then T cases follow.

Each case contains 3 lines. The first line contains two integers n, m (0 < n, m ≤ 105). The second line contains 2n integers s1, p1, s2, p2, ..., sn, pn (0=s1 < s2 < ... < sn ≤ 109, 109 ≥ p1 ≥ p2 ≥ ... ≥ pn ≥ 0). The price when printing no less than si but less than si+1 pages is pi cents per page (for i=1..n-1). The price when printing no less than sn pages is pn cents per page. The third line containing m integers q1 .. qm (0 ≤ qi ≤ 109) are the queries.

Output

For each query qi, you should output the minimum amount of money (in cents) to pay if you want to print qi pages, one output in one line.

Sample Input

1
2 3
0 20 100 10
0 99 100

Sample Output

0
1000
1000
 #include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
using namespace std;
typedef long long LL; LL a[],b[];
LL f[]; void prepare(LL n)
{
LL Min=b[n]*a[n];
LL ans;
f[n]=Min;
for(LL i=n-;i>=;i--)
{
ans=a[i]*b[i];
if(Min>ans)
Min=ans;
f[i]=Min;
}
}
LL EF(LL x,LL l,LL r)
{
LL mid=(l+r)/;
while(l<r)
{
if(a[mid]>x)
r=mid-;
else if(a[mid]<x)
l=mid;
else if(a[mid]==x)
return mid;
mid=(l+r+)/;
}
return mid;
} int main()
{
LL T;
LL i,n,m,x,k;
scanf("%lld",&T);
while(T--)
{
scanf("%lld%lld",&n,&m);
for(i=;i<=n;i++)
{
scanf("%lld%lld",&a[i],&b[i]);
}
prepare(n);
while(m--)
{
scanf("%lld",&x);
k=EF(x,,n);
LL ans=x*b[k];
if(k+<=n && ans>f[k+]) ans=f[k+];
printf("%lld\n",ans);
}
}
return ;
}

Alice's Print Service的更多相关文章

  1. HDU 4791 Alice's Print Service (2013长沙现场赛,二分)

    Alice's Print Service Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Ot ...

  2. 2013 ACM/ICPC 长沙现场赛 A题 - Alice's Print Service (ZOJ 3726)

    Alice's Print Service Time Limit: 2 Seconds      Memory Limit: 65536 KB Alice is providing print ser ...

  3. HDU 4791 Alice's Print Service 思路,dp 难度:2

    A - Alice's Print Service Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & ...

  4. A - Alice's Print Service ZOJ - 3726 (二分)

    Alice is providing print service, while the pricing doesn't seem to be reasonable, so people using h ...

  5. UVAlive 6611 Alice's Print Service 二分

    Alice is providing print service, while the pricing doesn't seem to be reasonable, so people using h ...

  6. HDU 4791 Alice's Print Service(2013长沙区域赛现场赛A题)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4791 解题报告:打印店提供打印纸张服务,需要收取费用,输入格式是s1 p1 s2 p2 s3 p3.. ...

  7. 2013 ACM区域赛长沙 A Alice’s Print Service HDU 4791

    题意:就是一个打印分段收费政策,印的越多,单张价格越低,输入需要印刷的数量,求最小印刷费用一个细节就是,比当前还小的状态可能是最后几个. #include<stdio.h> #includ ...

  8. HDU 4791 Alice&#39;s Print Service 水二分

    点击打开链接 Alice's Print Service Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K ( ...

  9. HDU 4791 &amp; ZOJ 3726 Alice&#39;s Print Service (数学 打表)

    题目链接: HDU:http://acm.hdu.edu.cn/showproblem.php?pid=4791 ZJU:http://acm.zju.edu.cn/onlinejudge/showP ...

随机推荐

  1. [Maven实战-许晓斌]-[第三章] Mave使用入门二(在IDE中的使用) [第四章] 案例的背景介绍

    创建maven项目

  2. [AIR] 利用File获取应用程序根目录

    import flash.filesystem.File; var file1:File = new File(File.applicationDirectory.resolvePath(" ...

  3. unicode 转换成中文

    unicode 转换成中文 + (NSString *)replaceUnicode:(NSString *)unicodeStr { NSString *tempStr1 = [unicodeStr ...

  4. 返回参数去掉xml格式,以纯json格式返回(转)

    Json 格式显示public static void Register(HttpConfiguration config) { //////////////设置不以xml格式返回 config.Fo ...

  5. 干掉Vivado幺蛾子(2)-- 快速替换debug probes

    目录 1. 什么是ECO 2. 操作步骤 参考文献: 我们做项目,进入找bug阶段时,需要用ILA捕获相关的信号.之前我做项目,每改动一次探针(debug probes),都要重新综合.实现,通常要花 ...

  6. ZOJ - 3946-Highway Project(最短路变形+优先队列优化)

    Edward, the emperor of the Marjar Empire, wants to build some bidirectional highways so that he can ...

  7. [转] git merge 将多个commit合并为一条之--squash 选项

    [FROM] https://blog.csdn.net/themagickeyjianan/article/details/80333645 1.一般的做法(直接git merge) Git相对于C ...

  8. 第六次 Scrum Meeting

    第六次 Scrum Meeting 写在前面 会议时间 会议时长 会议地点 2019/4/10 22:00 30min 大运村1号楼6F 附Github仓库:WEDO 例会照片 工作情况总结(4.10 ...

  9. win10操作系统系统,小米路由器,小米3 的问题

    注意 , 置顶 单独一篇 : { win10  局域网共享 小米路由器,操作盘太卡 } 开发中用专业版 , 别用家庭版 比如有远程桌面程序 和 HV 虚拟机 查看激活信息 和 是不是永久激活 参考 h ...

  10. 在循环中使用continue语句

    continue;//表示继续,当遇到continue语句时,则结束当次循环继续执行下一次循环  例子: class For09{ public static void main(String[ ]a ...