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 <string>
#include <string.h>
#include <map>
#include <stdio.h>
#include <algorithm>
#include <vector>
#define Min(a,b) ((a)<(b)?(a):(b))
using namespace std ;
const int Max_N = ;
typedef long long LL ;
LL dp[Max_N] ;
LL S[Max_N] ,P[Max_N] ;
int N ,M ; int find_id(LL x){
int Left = ;
int Right = N ;
int mid ;
int ans = -;
while(Left<=Right){
mid = (Left + Right)>> ;
if(S[mid] >= x){
Right = mid - ;
ans = mid ;
}
else
Left = mid + ;
}
return ans ;
} int main(){
int T ;
LL x;
scanf("%d",&T) ;
while(T--){
scanf("%d%d",&N,&M) ;
for(int i = ;i <= N ;i++)
scanf("%lld%lld",&S[i],&P[i]) ;
dp[N] = S[N] * P[N] ;
for(int i = N- ;i >= ;i--){
dp[i] = Min(S[i]*P[i],dp[i+]) ;
}
while(M--){
scanf("%lld",&x) ;
int id = find_id(x) ;
// cout<<x<<" "<<id<<endl ;
if(id == -){
printf("%lld\n",P[N]*x) ;
continue ;
}
if(S[id] == x)
printf("%lld\n",dp[id]) ;
else
printf("%lld\n",Min(dp[id],x*P[id-])) ;
}
}
return ;
}

The 2013 ACM-ICPC Asia Changsha Regional Contest - A的更多相关文章

  1. hduoj 4710 Balls Rearrangement 2013 ACM/ICPC Asia Regional Online —— Warmup

    http://acm.hdu.edu.cn/showproblem.php?pid=4710 Balls Rearrangement Time Limit: 6000/3000 MS (Java/Ot ...

  2. hduoj 4708 Rotation Lock Puzzle 2013 ACM/ICPC Asia Regional Online —— Warmup

    http://acm.hdu.edu.cn/showproblem.php?pid=4708 Rotation Lock Puzzle Time Limit: 2000/1000 MS (Java/O ...

  3. hduoj 4715 Difference Between Primes 2013 ACM/ICPC Asia Regional Online —— Warmup

    http://acm.hdu.edu.cn/showproblem.php?pid=4715 Difference Between Primes Time Limit: 2000/1000 MS (J ...

  4. hduoj 4712 Hamming Distance 2013 ACM/ICPC Asia Regional Online —— Warmup

    http://acm.hdu.edu.cn/showproblem.php?pid=4712 Hamming Distance Time Limit: 6000/3000 MS (Java/Other ...

  5. hduoj 4706 Herding 2013 ACM/ICPC Asia Regional Online —— Warmup

    hduoj 4706 Children's Day 2013 ACM/ICPC Asia Regional Online —— Warmup Herding Time Limit: 2000/1000 ...

  6. hduoj 4707 Pet 2013 ACM/ICPC Asia Regional Online —— Warmup

    http://acm.hdu.edu.cn/showproblem.php?pid=4707 Pet Time Limit: 4000/2000 MS (Java/Others)    Memory ...

  7. hduoj 4706 Children&#39;s Day 2013 ACM/ICPC Asia Regional Online —— Warmup

    http://acm.hdu.edu.cn/showproblem.php?pid=4706 Children's Day Time Limit: 2000/1000 MS (Java/Others) ...

  8. ACM ICPC Central Europe Regional Contest 2013 Jagiellonian University Kraków

    ACM ICPC Central Europe Regional Contest 2013 Jagiellonian University Kraków Problem A: Rubik’s Rect ...

  9. 2019-2020 ICPC, Asia Jakarta Regional Contest (Online Mirror, ICPC Rules, Teams Preferred)

    2019-2020 ICPC, Asia Jakarta Regional Contest (Online Mirror, ICPC Rules, Teams Preferred) easy: ACE ...

  10. 2013 ACM/ICPC Asia Regional Changsha Online - C Color Representation Conversion

    这个纯粹是一个细节题啊!!! 由于某个地方的浮点数比较写错了,WA了无数次啊…… 代码如下: #include<iostream> #include<cstdio> #incl ...

随机推荐

  1. ABP系列文章总目录:

    转自:http://www.cnblogs.com/mienreal/p/4528470.html 1.ABP总体介绍 2.ASP.NET Boilerplate入门 3.ABP分层架构 4.ABP模 ...

  2. Spring实战2:装配bean—依赖注入的本质

    主要内容 Spring的配置方法概览 自动装配bean 基于Java配置文件装配bean 控制bean的创建和销毁 任何一个成功的应用都是由多个为了实现某个业务目标而相互协作的组件构成的,这些组件必须 ...

  3. Python 定制类与其对象的创建和应用

    1.创建新类Athlete,创建两个唯一的对象实例sarah james,他们会继承Athlete类的特性 >>> class Athlete: def __init__(self, ...

  4. 《黄聪:手机移动站SEO优化教程》4、如何实现手机移动网站和PC站点的自主适配

    视频地址:http://www.tudou.com/programs/view/v4Hur5vjav4/ 1.自主适配 A:站点自己做好PC与手机之间的适配,以及手机站各个版式之间的适配.当手机用户通 ...

  5. Java 新IO

       NIO提供全新的底层I/O模型.与最初的java.io包中面向流(stream-oriented)概念不同,NIO采用了面向块的概念(block-oriented).在尽可能的情况下,I/O的操 ...

  6. JVM 类型的生命周期学习

    Java虚拟机通过装载.连接和初始化一个JAVA类型,使该类型可以被正在运行的JAVA程序所使用,其中,装载就是把二进制形式的JAVA类型读入JAVA虚拟机中:而连接就是把这种读入虚拟机的二进制形式的 ...

  7. A^B问题

    题目:输入包括两个正整数 A 和 B(1 <= A, B <= 10000),A 和 B 之前用空格隔开 ★数据输出 输出一行,若 A ^ B < 10000,则直接输出结果(不包含 ...

  8. requesting java ast from selection

    遇到這個錯誤是因為在eclipse中選擇了maven->update project.接著就不斷的出現題目上的錯誤,然後就提示是否退出workbench. 查看了一下項目的compile jre ...

  9. ylbtech-Unitity-CS:Delegates

    ylbtech-Unitity-CS:Delegates 1.A,效果图返回顶部 Invoking delegate a: Hello, A! Invoking delegate b: Goodbye ...

  10. Linux下SVN服务器安装配置及客户端安装说明

    原文地址:http://wenku.baidu.com/link?url=h3dVAMx4azpOXEND5HQEE6nliE8-zc0GSQ03yv4cUs1vXMALXF64UsK7kT7kXm_ ...