The 2013 ACM-ICPC Asia Changsha Regional Contest - A
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的更多相关文章
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- hduoj 4706 Children'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) ...
- 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 ...
- 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 ...
- 2013 ACM/ICPC Asia Regional Changsha Online - C Color Representation Conversion
这个纯粹是一个细节题啊!!! 由于某个地方的浮点数比较写错了,WA了无数次啊…… 代码如下: #include<iostream> #include<cstdio> #incl ...
随机推荐
- HTML 标题
在 HTML 文档中,标题很重要. HTML 标题 标题(Heading)是通过 <h1> - <h6> 等标签进行定义的. <h1> 定义最大的标题.<h6 ...
- matlab 画三维图函数
matlab三维绘图 http://blog.sina.com.cn/s/blog_6d5ffd0d0100lyah.html Matlab绘图系列之高级绘图 http://blog.163.com/ ...
- 深入了解iPad上的MouseEvent【转】
iPad上没有鼠标,所以手指在触发触摸事件(TouchEvent)的时候,系统也会产生出模拟的鼠标事件(MouseEvent). 这对于普通网页的浏览需求而言,基本可以做到与PC端浏览器无明显 ...
- PHP header函数大全
PHP header函数大全 header('Content-Type: text/html; charset=utf-8'); header('Location: http://www.php-no ...
- db4o种纯对象数据库引擎
db4o是一种纯对象数据库,相对于传统的关系数据库+ORM,db4o具有以下好处:1)以存对象的方式存取数据(废话--,不过你考虑一下完全以对象的方式去考虑数据的存取对传统的数据库设计思维来说是多么大 ...
- 什么是编解码器codec
编解码器(英语:codec)指的是一个能够对一个信号或者一个数据流进行编解码操作的设备或者程序.这里指的变换既包括将信号或者数据流进行编码(通常是为了传输.存储或者加密)或者提获取到一个编码流的操作, ...
- Hibernate4日志及配置文件
1. 确定要使用日志的实现log4j 2. Slf4japi.jar和log4j的jar包放入classpath,(slf4j-log4j.jar) 3. 编写log4j.properties 4. ...
- Hadoop 2.6.0集群搭建
yum install gcc yum install gcc-c++ yum install make yum install autoconfautomake libtool cmake yum ...
- AP_HZ Party和Supplier、Bank表关系详解
2014-06-26 Created By BaoXinjian
- VMware和CentOS7安装和配置
准备工作: 下载: 1.VMware-workstation-full-10.0.0-1295980 2.CentOS-7-x86_64-DVD-1511.iso 安装: 1.VMware-works ...