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
 
Source
 
/* ***********************************************
Author :pk28
Created Time :2015/10/15 20:05:30
File Name :changchun1.cpp
************************************************ */
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <stdlib.h>
#include <iomanip>
#include <list>
#include <deque>
#include <stack>
#define ull unsigned long long
#define ll long long
#define mod 90001
#define INF 1e13
#define maxn 100070
#define cle(a) memset(a,0,sizeof(a))
const ull inf = 1LL << ;
const double eps=1e-;
using namespace std; bool cmp(int a,int b){
return a>b;
}
int n,m;
ll x[maxn],p[maxn];
ll minn[maxn];
int main()
{
#ifndef ONLINE_JUDGE
freopen("in.txt","r",stdin);
#endif
//freopen("out.txt","w",stdout);
int t;
cin>>t;
while(t--){
cin>>n>>m;
for(int i=;i<=n;i++){
scanf("%lld %lld",&x[i],&p[i]);
}
minn[n+]=INF;
for(int i=n;i>=;i--){
minn[i]=min(minn[i+],p[i]*x[i]);
}
ll a,ans;
for(int i=;i<=m;i++){
scanf("%lld",&a);
int pos=lower_bound(x+,x++n,a)-x;
ans=min(a*p[pos-],minn[pos]);
printf("%lld\n",ans);
}
}
return ;
}

UVAlive 6611 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. Alice's Print Service

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

  5. 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 ...

  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. Python入门--2--继续学习

    继续学习小甲鱼 一.python比较操作符 == :判断左边是否等于右边 != : 判断左边是否不能右边 二. if while判断语句 栗子: temp = input ("sha shu ...

  2. AC日记——租用游艇 洛谷 P1359

    题目描述 长江游艇俱乐部在长江上设置了n 个游艇出租站1,2,…,n.游客可在这些游艇出租站租用游艇,并在下游的任何一个游艇出租站归还游艇.游艇出租站i 到游艇出租站j 之间的租金为r(i,j),1& ...

  3. Flutter学习(一)——搭建开发环境(Windows)

    久闻 Flutter 大名,今天终于有时间体验一下了 ٩(๑>◡<๑)۶ 官网:https://flutter.dev/ 中文官网:https://flutterchina.club/ 一 ...

  4. 【JSON注解】注解@JsonIgnoreProperties和@JsonIgnore的另一个使用情况

    之前关于这两个注解,是用在JSON循环引用的情况上,那么现在关于这两个注解,还可以使用在另外一种情况上 即: 一般标记在属性或者方法上,返回的json数据即不包含该属性 关于这种情况在什么时候会遇到呢 ...

  5. 五步掌握Git的基本开发使用命令

    第一步:设置全局变量: git config --global user.name "gang.li" git config --global user.email "l ...

  6. BUPT复试专题—最近公共祖先(2014软院)

    题目描述 给出一棵有N个节点的有根树TREE(根的编号为1),对于每组查询,请输出树上节点u和v的最近公共祖先. 最近公共祖先:对于有向树TREE的两个结点u,v.最近公共祖先LCA(TREE u,v ...

  7. linux 源码编译安装apache

    cc1 是c语言的编译器.

  8. nginx配置初步

    nginx配置初步 1,切换至nginx目录,找到配置文件目录 cd /etc/nginx/conf.d 2,拷贝一份conf文件 sudo cp default.conf head.conf 3,进 ...

  9. 赵雅智_Swift(2)_swift常量和变量

    分号 Swift 并不强制要求你在每条语句的结尾处使用分号(;) 你打算在同一行内写多条独立的语句必需要用分号 let cat = "? ?? ? "; println(cat) ...

  10. 微信小程序 - 提取字体图标与其优化

    微信小程序,无论是字体图标还是图标,都差不多,只不过是为了以后字体图标修改方便,或者加效果方便而使用它而已! 1. 下载font-awesome http://fontawesome.dashgame ...