题目链接:http://codeforces.com/problemset/problem/729/C

C. Road to Cinema
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

Vasya is currently at a car rental service, and he wants to reach cinema. The film he has bought a ticket for starts in t minutes.
There is a straight road of length s from the service to the cinema. Let's introduce a coordinate system so that the car rental service
is at the point 0, and the cinema is at the point s.

There are k gas stations along the road, and at each of them you can fill a car with any amount of fuel for free! Consider that this
operation doesn't take any time, i.e. is carried out instantly.

There are n cars in the rental service, i-th
of them is characterized with two integers ci and vi —
the price of this car rent and the capacity of its fuel tank in liters. It's not allowed to fuel a car with more fuel than its tank capacity vi.
All cars are completely fueled at the car rental service.

Each of the cars can be driven in one of two speed modes: normal or accelerated. In the normal mode a car covers 1 kilometer in 2minutes,
and consumes 1 liter of fuel. In the accelerated mode a car covers 1 kilometer
in 1 minutes, but consumes 2 liters
of fuel. The driving mode can be changed at any moment and any number of times.

Your task is to choose a car with minimum price such that Vasya can reach the cinema before the show starts, i.e. not later than in tminutes.
Assume that all cars are completely fueled initially.

Input

The first line contains four positive integers nks and t (1 ≤ n ≤ 2·105, 1 ≤ k ≤ 2·105, 2 ≤ s ≤ 109, 1 ≤ t ≤ 2·109) —
the number of cars at the car rental service, the number of gas stations along the road, the length of the road and the time in which the film starts.

Each of the next n lines contains two positive integers ci and vi (1 ≤ ci, vi ≤ 109) —
the price of the i-th car and its fuel tank capacity.

The next line contains k distinct integers g1, g2, ..., gk (1 ≤ gi ≤ s - 1) —
the positions of the gas stations on the road in arbitrary order.

Output

Print the minimum rent price of an appropriate car, i.e. such car that Vasya will be able to reach the cinema before the film starts (not later than in t minutes).
If there is no appropriate car, print -1.

Examples
input
3 1 8 10
10 8
5 7
11 9
3
output
10
input
2 2 10 18
10 4
20 6
5 3
output
20
Note

In the first sample, Vasya can reach the cinema in time using the first or the third cars, but it would be cheaper to choose the first one. Its price is equal to 10, and the capacity of its fuel tank is 8. Then Vasya can drive to the first gas station in the accelerated mode in 3minutes, spending 6 liters of fuel. After that he can full the tank and cover 2 kilometers in the normal mode in 4 minutes, spending 2liters of fuel. Finally, he drives in the accelerated mode covering the remaining 3 kilometers in 3 minutes and spending 6 liters of fuel.

题解:

1.由于题目没说明车越贵,容量越大,所以需要将价格贵但容量小的车丢弃。

做法是:先按车的容量升序排列,然后用单调队列处理,使得队列中的车的价格也递增。

2.二分车的下标。

单调队列:

int N = ;
for(int i = ; i<=n; i++)
{
while(N>= && a[i]<=a[N]) N--; // a[i]<a[N] 还是 a[i]<=a[N]视情况而定。
a[++N] = a[i];
}

代码如下:

 #include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const double eps = 1e-;
const int INF = 2e9;
const LL LNF = 9e18;
const int mod = 1e9+;
const int maxn = 2e5+; LL n,k,s,t, g[maxn];
LL N; struct node
{
LL c,v;
bool operator<(const node&x)const{
return v<x.v;
}
}a[maxn]; void init()
{
cin>>n>>k>>s>>t;
for(int i = ; i<=n; i++)
scanf("%lld%lld",&a[i].c, &a[i].v);
for(int i = ; i<=k; i++)
scanf("%lld",&g[i]); g[++k] = s; //将终点也放进去
sort(g+,g++k); N = ;
sort(a+,a++n); //按车的汽油容量升序排序
for(int j = ; j<=n; j++) //单调队列
{
while(N>= && a[j].c<=a[N].c) N--;
a[++N] = a[j];
}
} int test(int pos)
{
LL x, y, T = ; //x为以快速行驶的路程, y为以常速行驶的路程
LL capa = a[pos].v;
for(int i = ; i<=k; i++)
{
LL dis = g[i]-g[i-]; if(capa<dis) //以常速都跑不完
return ;
else if(capa<*dis ) //快速+常速 or 常速
x = capa - dis, y = capa - *x;
else //可以全程以快速行驶
x = dis, y = ; T += x + *y; //更新时间
if(T>t) return ; //超时
}
return ;
} void solve()
{
LL l = , r = N;
while(l<=r)
{
LL mid = (l+r)>>;
if(test(mid))
r = mid - ;
else
l = mid + ;
}
printf("%lld\n",l==N+? - : a[l].c);
} int main()
{
init();
solve();
}

Technocup 2017 - Elimination Round 2 C. Road to Cinema —— 二分的更多相关文章

  1. Codeforces Round #380 (Div. 2, Rated, Based on Technocup 2017 - Elimination Round 2)C. Road to Cinema 二分

    C. Road to Cinema time limit per test 1 second memory limit per test 256 megabytes input standard in ...

  2. codeforces Codeforces Round #380 (Div. 1, Rated, Based on Technocup 2017 - Elimination Round 2)// 二分的题目硬生生想出来ON的算法

    A. Road to Cinema 很明显满足二分性质的题目. 题意:某人在起点处,到终点的距离为s. 汽车租赁公司提供n中车型,每种车型有属性ci(租车费用),vi(油箱容量). 车子有两种前进方式 ...

  3. Codeforces Round #389 (Div. 2, Rated, Based on Technocup 2017 - Elimination Round 3) C

    Description Santa Claus has Robot which lives on the infinite grid and can move along its lines. He ...

  4. Codeforces Round #389 (Div. 2, Rated, Based on Technocup 2017 - Elimination Round 3) B

    Description Santa Claus decided to disassemble his keyboard to clean it. After he returned all the k ...

  5. Codeforces Round #389 (Div. 2, Rated, Based on Technocup 2017 - Elimination Round 3) A

    Description Santa Claus is the first who came to the Christmas Olympiad, and he is going to be the f ...

  6. Codeforces Round #389 (Div. 2, Rated, Based on Technocup 2017 - Elimination Round 3) D. Santa Claus and a Palindrome STL

    D. Santa Claus and a Palindrome time limit per test 2 seconds memory limit per test 256 megabytes in ...

  7. Codeforces Round #389 (Div. 2, Rated, Based on Technocup 2017 - Elimination Round 3) E. Santa Claus and Tangerines

    E. Santa Claus and Tangerines time limit per test 2 seconds memory limit per test 256 megabytes inpu ...

  8. Codeforces Round #380 (Div. 1, Rated, Based on Technocup 2017 - Elimination Round 2)

    http://codeforces.com/contest/737 A: 题目大意: 有n辆车,每辆车有一个价钱ci和油箱容量vi.在x轴上,起点为0,终点为s,中途有k个加油站,坐标分别是pi,到每 ...

  9. Codeforces Round #380 (Div. 2, Rated, Based on Technocup 2017 - Elimination Round 2) E. Subordinates 贪心

    E. Subordinates time limit per test 1 second memory limit per test 256 megabytes input standard inpu ...

随机推荐

  1. Java原子类及内部原理

    一.引入 原子是世界上的最小单位,具有不可分割性.比如 a=0:(a非long和double类型) 这个操作是不可分割的,那么我们说这个操作是原子操作.再比如:a++: 这个操作实际是a = a + ...

  2. GDKOI賽前總結

    @(賽前總結)[GDKOI2017] 提一些比賽時要注意的事項: 賽前先把讀入優化/輸出優化的模板調試好, 加入缺省源中. 注意不要出錯, 輸出為0或者負數的情況要特盤; 讀入輸出文件名不要搞錯; 由 ...

  3. python获取对象的信息

    Types 判断基本数据类型可以直接写int,str等,但如果要判断一个对象是否是函数怎么办?可以使用types模块中定义的常量. >>> import types >> ...

  4. 【redis】4.spring boot集成redis,实现数据缓存

    参考地址:https://spring.io/guides/gs/messaging-redis/ ================================================== ...

  5. Samp免流软件以及地铁跑酷的自校验分析

    [文章标题]:Samp免流软件以及地铁跑酷的自校验分析 [文章作者]: Ericky [作者博客]: http://blog.csdn.net/hk9259 [下载地址]: 自行百度 [保护方式]: ...

  6. Headroom.js插件用法

    一.Headroom.js是什么? Headroom.js是一个轻量级.高性能的JS小工具(不依赖不论什么工具库.),它能在页面滚动时做出响应. 此页面顶部的导航条就是一个鲜活的案例,当页面向下滚动时 ...

  7. Naive Bayesian文本分类器

    贝叶斯学习方法中有用性非常高的一种为朴素贝叶斯学习期,常被称为朴素贝叶斯分类器. 在某些领域中与神经网络和决策树学习相当.尽管朴素贝叶斯分类器忽略单词间的依赖关系.即如果全部单词是条件独立的,但朴素贝 ...

  8. Upgrade to postgresql 9.5

        Add postgresql apt repo.. according to your distribution (utopic, trusty, jessie, wheezy and etc ...

  9. String,StringBuilder性能对照

    import java.util.Date; import java.util.UUID; /**  * 測试String,StringBuilder性能,推断什么时候改用String,什么时候该用S ...

  10. Deployment相对ReplicaSet优势

    系列目录 RS与Deployment主要用于替代RC.RS的全称为Replica Set.相对于RC,RS与Deployment的优势如下: RC只支持基于等式的selector,如env=dev或者 ...