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 ...
随机推荐
- kali linux之应用层Dos
应用层服务漏洞: 服务代码存在漏洞,遇异常提交数据时程序崩溃 应用处理大量并发请求能力有限,被拒绝的是应用或OS 缓冲区溢出漏洞: 向目标函数随机提交数据,特定情况下数据覆盖临近寄存器或内存 影响:远 ...
- jquery实现简易的计算器
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- google hack使用集锦
转载:https://blog.csdn.net/weixin_42127015/article/details/84472777 关于google hack的几个基础过滤器使用[请务必谨记,过滤器虽 ...
- 移动端滑动时页面惯性滑动overflow-scrolling: touch
-webkit-overflow-scrolling:auto | touch; auto: 普通滚动,当手指从触摸屏上移开,滚动立即停止 touch:滚动回弹效果,当手指从触摸屏上移开,内容会保持一 ...
- 用hashmap实现redis有什么问题
1.容量问题 hashmap是有最大容量的 2.时效问题 redis可以持久化,也可以定时时间 hashmap不可以持久化 3.线程并发问题 hashmap不是线程安全的(并且:多线程同时调用hash ...
- 在bootstrap modal 中加载百度地图的信息窗口失效解决方法
这个问题其实很傻,解决方法没有任何技术含量,只是记录下工作中发生的事. 前阵子给一个汽车集团客户做了一个经销商查询系统,其中一个功能是使用地图标注经销商店面地址,并且实现导航功能. 页面演示地址:ht ...
- 递归demo
递归算法就是直接或间接调用自己的算法 public static void main(String[] args) { int m = sum(9); System.out.println(m); } ...
- GridView控件详解
一.介绍 GridView控件一表格形式显示数据源中的数据.提供对列进行排序.分页以及编辑.删除单个记录的功能. 二.绑定数据源 第一种使用DataSourceID属性.可以直接把GridView控件 ...
- Go语言包管理工具Glide
Go语言包管理工具用于管理Go项目的库和库的依赖引用. 包管理工具普遍会在Go项目根目录生成Vendor文件夹并自动下载该Go项目需要的库. Go语言有很多开源的包管理工具,这里主要介绍Glide ...
- CentOS下安装官方RPM包的MySQL后找不到my.cnf
PS:昨天一同事问我说他用MySQL 5.5官方的rpm包安装了,但是在/etc/下面没有my.cnf配置文件.官方rpm包安装的mysql默认确实是没有/etc/my.cnf. 为什么没有这个文件而 ...