题目链接: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. chattr&chown&cat&cut&useradd&passwd&chage&usermod

    1.用chattr命令防止系统中某个关键文件被修改 chattr +i /etc/resolv.conf chattr -i /etc/resolv.conf 要想修改此文件就要把i属性去掉 lsat ...

  2. Android 桌面小部件

    1. 添加AppWidgetProvider 实际上就是个带有界面的BroadcastReceiver public class SimpleWidgetProvider extends AppWid ...

  3. [Bzoj4942][Noi2017]整数(线段树)

    4942: [Noi2017]整数 Time Limit: 50 Sec  Memory Limit: 512 MBSubmit: 363  Solved: 237[Submit][Status][D ...

  4. 【java】spring项目中 对entity进行本类间的克隆

    方法1: [使用spring自带BeanUtils实现克隆] [要求:需要被克隆的类实现Cloneable接口并且重写clone()方法] >例子: >>实体: package co ...

  5. 使用XtraGrid自定义列计算 z

    绑定Master-Detail 关系 数据也是数据显示的一种方式,此实例使用后台代码创建数据源并绑定到gridcontrol. 其实方式参见:点击打开链接 先看效果图(默认方式) 直接给出后台代码,主 ...

  6. Mac下export生效

    在Terminal下用export PS1=XXX   修改完后,本次生效,但是重新启动Teminal后又恢复到默认格式.如何才能永久保存自定义的提示符格式呢? 1,~下面本来没有 .bash_pro ...

  7. HDU1506 Largest Rectangle in a Histogram (动规)

    Largest Rectangle in a Histogram Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 ...

  8. [Algorithms] Sort an Array with a Nested for Loop using Insertion Sort in JavaScript

    nsertion sort is another sorting algorithm that closely resembles how we might sort items in the phy ...

  9. mysql主从一致问题

    https://www.cnblogs.com/gomysql/p/3662264.html

  10. Android——通过Intent传递一些二进制数据的方法有哪些

    1.方法 (1)使用Serializable接口实现序列化.利用Bundle.putSerializable(Key, Object);这里objec对象需要实现serializable接口. (2) ...