Alice's Print Service
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的更多相关文章
- 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 ...
- 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 ...
- HDU 4791 Alice's Print Service 思路,dp 难度:2
A - Alice's Print Service Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & ...
- 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 ...
- UVAlive 6611 Alice's Print Service 二分
Alice is providing print service, while the pricing doesn't seem to be reasonable, so people using h ...
- HDU 4791 Alice's Print Service(2013长沙区域赛现场赛A题)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4791 解题报告:打印店提供打印纸张服务,需要收取费用,输入格式是s1 p1 s2 p2 s3 p3.. ...
- 2013 ACM区域赛长沙 A Alice’s Print Service HDU 4791
题意:就是一个打印分段收费政策,印的越多,单张价格越低,输入需要印刷的数量,求最小印刷费用一个细节就是,比当前还小的状态可能是最后几个. #include<stdio.h> #includ ...
- HDU 4791 Alice's Print Service 水二分
点击打开链接 Alice's Print Service Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K ( ...
- HDU 4791 & ZOJ 3726 Alice's Print Service (数学 打表)
题目链接: HDU:http://acm.hdu.edu.cn/showproblem.php?pid=4791 ZJU:http://acm.zju.edu.cn/onlinejudge/showP ...
随机推荐
- TensorFlow支持GPU配置问题
目录 Tensorflow-GPU 环境条件 现有硬件 现有软件 硬件要求 软件要求 步骤 0.Visual studio 1.下载安装显卡驱动 2.下载对应版本 CUDA 3.安装配置 cuDNN ...
- [转] 以普通用户启动的Vim如何保存需要root权限的文件
[转] 以普通用户启动的Vim如何保存需要root权限的文件 在Linux上工作的朋友很可能遇到过这样一种情况,当你用Vim编辑完一个文件时,运行:wq保存退出,突然蹦出一个错误: E45: 'rea ...
- python库安装如:requests,selenium等
安装方式: 1.pip安装: 如:pip install requests 2.wheel安装: 在PyPI上下载对应的wheel文件:如要下载requests的wheel文件,打开:http://p ...
- css样式之标签的查找
css的组成部分:选择器和声明 css的注释: /*这是注释*/ <!DOCTYPE html> <html lang="zh-CN"> <head& ...
- Navicat 连接腾讯云
1.dos窗口下进入mysql,进行远程登录授权 (1)进行授权 mysql>GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '1 ...
- linux内核修炼之道
华清远见·任桥伟 人民邮电 2010 内核不学,岂能理解?今天开始正式学习内核原理 linux 发行版本Mint. cat /etc/issue # sudo lsb_release - ...
- PPT免费模板网站
OfficePlus|微软PPT官方模版库 优品PPT 稻壳儿
- gcc 常用命令
gcc编译器 $ gcc -o XX.exe XXX.c ddd.c $ gcc -o XX.asm -S XXX.c 编译生成可执行文件,并执行程序,缺省的时候,gcc 编译出来的文件是a.out ...
- thymeleaf常用语法
常用标签语法:①th:text<span th:text="${name}">1</span>注释:如果${name}有值则将替换掉1的值,若无则为1 ②t ...
- dgango 报错: Timeout when reading response headers from daemon process
问题: image = np.asarray(bytearray(f.read()), dtype="uint8")cv2_img = cv2.imdecode(image, cv ...