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 ...
随机推荐
- 【linux】top命令详解
常用命令 top -d 3 ##每3秒监控一次 [root@TG1704 log]# top top - 14:06:23 up 70 days, 16:44, 2 users, load avera ...
- Windows下使用批处理设置IP地址,DNS
自动获取IP地址: echo 本地连接 改成你想要改的连接名 比如 无线网络连接set cname=本地连接 echo %cname% 正在设置自动获得IP地址,请稍等...... netsh int ...
- 【Hadoop测试程序】编写MapReduce测试Hadoop环境
我们使用之前搭建好的Hadoop环境,可参见: <[Hadoop环境搭建]Centos6.8搭建hadoop伪分布模式>http://www.cnblogs.com/ssslinppp/p ...
- php获取一年中某一周的开始和结束时间
PHP来获取一年中的每星期的开始日期和结束日期的代码 函数get_week()通过传入参数$year年份,获取当年第一天和最后一天所在的周数,计算第一周的日期,通过循环获取每一周的第一天和最后一天的日 ...
- nsq的erlang客户端
nsq是基于golang开发的分布式消息系统,这里仅仅贴个和erlang之间的通信demo rebar-creator create-app test_nsq rebar.config % -*- e ...
- java.io.FileNotFoundException:SESSIONS.ser (系统找不到指定的路径。)
问题如下: java.io.FileNotFoundException: E:\apache-tomcat-8.0.37\work\Catalina\localhost\20161013Shoppin ...
- POJ 2311 Cutting Game(Nim博弈-sg函数/记忆化搜索)
Cutting Game 题意: 有一张被分成 w*h 的格子的长方形纸张,两人轮流沿着格子的边界水平或垂直切割,将纸张分割成两部分.切割了n次之后就得到了n+1张纸,每次都可以选择切得的某一张纸再进 ...
- NeHe OpenGL教程 第二课:多边形
前言 声明,此 NeHe OpenGL教程系列文章由51博客yarin翻译(2010-08-19),本博客为转载并稍加整理与修改.对NeHe的OpenGL管线教程的编写,以及yarn的翻译整理表示感谢 ...
- Jquery each和map 的区别
1,回调函数的参数顺序相反,each:i,elem,map:elem,i 2,返回值不同,map返回一个新的数组,each返回原始数组 回调的返回值,each只能返回 true 和 false,map ...
- JAVA if条件语句,switch多分支结构,与逻辑运算符
一.if条件语句 示例: import java.util.Scanner; public class Test{ public static void main(String[] args){ Sc ...