UVAlive 6611 Alice's Print Service 二分
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.
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.
/* ***********************************************
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 二分的更多相关文章
- 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 ...
- 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 ...
- HDU 4791 Alice's Print Service 思路,dp 难度:2
A - Alice's Print Service Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & ...
- Alice's Print Service
Alice's Print Service Time Limit: 2 Seconds Memory Limit: 65536 KB Alice is providing print ser ...
- 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 ...
- HDU 4791 Alice's Print Service(2013长沙区域赛现场赛A题)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4791 解题报告:打印店提供打印纸张服务,需要收取费用,输入格式是s1 p1 s2 p2 s3 p3.. ...
- 2013 ACM区域赛长沙 A Alice’s Print Service HDU 4791
题意:就是一个打印分段收费政策,印的越多,单张价格越低,输入需要印刷的数量,求最小印刷费用一个细节就是,比当前还小的状态可能是最后几个. #include<stdio.h> #includ ...
- HDU 4791 Alice's Print Service 水二分
点击打开链接 Alice's Print Service Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K ( ...
- HDU 4791 & ZOJ 3726 Alice's Print Service (数学 打表)
题目链接: HDU:http://acm.hdu.edu.cn/showproblem.php?pid=4791 ZJU:http://acm.zju.edu.cn/onlinejudge/showP ...
随机推荐
- PC端有什么好用的倍速播放的软件?
倍速播放的目的是让自己可以以更快的速度去看视频, 加快获取信息的效率 potplay吧,和KMP是一个作者.加速播放快捷键是c,减速时x,z恢复正常.下载官网 Global Potplayer
- 洛谷 [P3265] 装备购买
线性基 通过题目描述可以感觉到就是要求线性基, 线性基的求法是高斯消元,消完以后剩下的x的系数非 0 的就是线性基 本题有一个贪心策略,每次挑选价格最小的来消掉其他的元 //可以快排预处理 #incl ...
- net3:Button的CommandName使用,AdRotator,BulletedList的使用
原文发布时间为:2008-07-29 -- 来源于本人的百度文章 [由搬家工具导入] using System;using System.Data;using System.Configuration ...
- Yii 之控制器创建使用
在根目录下的controllers目录下创建控制器HelloController.php: <?php namespace app\controllers; use yii\web\Contro ...
- Codeforces 486D Valid Sets (树型DP)
题目链接 Valid Sets 题目要求我们在一棵树上计符合条件的连通块的个数. 满足该连通块内,点的权值极差小于等于d 树的点数满足 n <= 2000 首先我们先不管这个限制条件,也就是先考 ...
- T1405 奶牛的旅行 codevs
http://codevs.cn/problem/1405/ 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 黄金 Gold 题目描述 Description 农民John的农场 ...
- GRYZY #8. 公交车
公交车(bus) Time Limit:1000ms Memory Limit:128MB 题目描述 LYK在玩一个游戏. 有k群小怪兽想乘坐公交车.第i群小怪兽想从xi出发乘坐公交车到yi.但公交车 ...
- java设计模式图
一.什么是设计模式 ...
- svn简单介绍
版本号控制(Revision control)是维护project蓝图的标准做法,能追踪project蓝图从诞生一直到定案的过程.是一种记录若干文件内容变化.以便将来查阅特定版本号修订情况的系统. 能 ...
- 零售连锁行业SOA化解决方式
零售连锁行业面临的问题 1.店铺老化.营销手段单一落后. 2.管理模式的不科学,我国零售企业在起家时候并没有一套完好的科学的管理及考评系统的存在.而且在企业的发展过程中并未学习建立.对于人才的吸引.培 ...