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. JDBC Driver

    Infomix Driver: com.informix.jdbc.IfxDriver JDBC URL : jdbc:informix-sqli://<host>:<port> ...

  2. dns 服务器配置

    1.安装 named 2.配置如下文件: /etc/named.conf // 2 // named.conf 3 // 4 // Provided by Red Hat bind package t ...

  3. python主要用来做什么

    python这门编程语言在国外极受欢迎,但在国内使用还不是极普遍. 由于python编程效率极高,现在国内的使用者也开始变得越来越多. python主要用来做什么?这个语言到底有哪些作用呢? 下面主是 ...

  4. QT5中的信号与槽与C++ 11的function的配合

    最近将公司的界面开发库从WX转换到了QT,有了信号和槽,原本我们在使用WX的时候,为了使用信号,我们是使用BOOST的signal2库,到了QT有了信号槽,这个就没什么必要了 但是前段时间使用QT发现 ...

  5. Tomcat无法启动:org.apache.catalina.LifecycleException: Failed to start component 问题解决

    问题如下:需要使用到数据库mysql,于是将mysql-connector-java-5.1.30-bin.jar的数据库驱动复制到WEE-INF/lib目录下.点击运行,但是服务器无法启动. 控制台 ...

  6. [linux basic 基础]----同步信号量

    直接使用一个共享变量,来是两个线程之间进行切换是非常笨拙而且没有效率的:信号量--互斥量--这两者是相互通过对方来实现的:比如,如果想控制某一时刻只有一个线程可以访问一些共享内存,使用互斥量要自然一些 ...

  7. unity客户端与c++服务器之间的简单通讯_1

    // 服务器 # pragma once using namespace std; # include <iostream> # include <string> # incl ...

  8. DBA_Oracle Erp版本升级12.1.1到R12.1.3(案例)

    20150506 Created By BaoXinjian

  9. BPEL_Oracle BPEL新一代工作流介绍(概念)

    2014-11-02 Created By BaoXinjian

  10. CLR和JIT

    在使用IDE进行编译的时候,这个过程具体的叫法是,使用编译器面向CLR来生成代码.对于不同的开发语言,使用的的编译器也不一样,但是生成的代码都一样. “无论选用哪一个编译器,结果都是一个托管模块.” ...