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. JVM_垃圾收集器

    最近刚好有时间,就简单的看了下JVM的几种垃圾回收器,它们都是计算机历史发展的产物,先简单的做一个整理,并没有哪一款垃圾收集器就一定是最优,还需要结合使用场景.参数配置等进行考量,根据系统情况搭配出尽 ...

  2. php 调用银联接口 【转载】

    首先要开启openssl开启方法为 openssl证书放在Apache的bin目录中. 其中的php_openssl.dll,ssleay32.dll,libeay32.dll,3个文件拷到windo ...

  3. centos6和ubuntu14搭建sftp

    参考 http://blog.csdn.net/xinxin19881112/article/details/46831311 一. 在Centos 6.6环境使用系统自带的internal-sftp ...

  4. iOS核心动画之视觉效果

    圆角 cornerRadius确定圆角的大小 masksToBounds确定要不要裁减圆角以外的界面 图层边框 borderWidth 边框的粗细,point是衡量值. borderColor 边框的 ...

  5. mysql基础操作学习笔记(一)

    1前期准备: SQL语言包涵以下4个部分: (1)数据定义语言(DDL):包括DROP, CREATE, ALTER等语句 (2)数据操纵语言(DML):包括INSERT, UPDATE, DELET ...

  6. 几个常见用于解决nginx负载均衡的session共享问题的办法

    查了一些资料,看了一些别人写的文档,总结如下,实现nginx session的共享: PHP服务器有多台,用nginx做负载均衡,这样同一个IP访问同一个页面会被分配到不同的服务器上,如果sessio ...

  7. jquery 实现动画效果(各种方法)

    1.show()和hide()和toggle()(这是show和hide的一个综合,一个按钮就实现显示和隐藏) 效果: 代码: <button type="button" c ...

  8. springmvc.xml配置

    <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.sp ...

  9. python 模块和包以及他们的导入关系

    一 模块 1 什么是模块? 常见的场景:一个模块就是一个包含了python定义和声明的文件,文件名就是模块名字加上.py的后缀. 但其实import加载的模块分为四个通用类别: 1 使用python编 ...

  10. CentOS&.NET Core初试-2-安装.NET Core SDK和发布网站

    系列目录 CentOS的安装和网卡的配置 安装.NET Core SDK和发布网站 Nginx的安装和配置 安装守护服务(Supervisor) 安装.NET Core SDK 注册Microsoft ...