题目链接: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. Atcoder Grand Contest 024

    A 略 B 略 C 略 D(构造分形) 题意: 给出一个由n个点的组成的树,你可以加一些点形成一个更大的树.对于新树中的两个点i和j,如果以i为根的树与以j为根的树是同构的那么i和j颜色可以相同.问最 ...

  2. layDate 日期与时间组件 入门

    首先第一步 在官方下载layDate文件.layUI官网:http://layer.layui.com/    https://www.layui.com/laydate/ layDate文件的下载步 ...

  3. 1.搭建maven,eclipse创建maven项目

    1.下载maven包,下载地址为:http://maven.apache.org/download.cgi 2.解压zip包 3.eclipse 引入maven: window-Preferences ...

  4. BT服务器的搭建(tracker-P2P服务器架设)(转)

    文章虽然有点老,但原理差不多. 继上一篇文章(http://www.cnblogs.com/EasonJim/p/6601146.html)介绍了BT的原理,现在来看下BT服务端搭建的原理. 一.BT ...

  5. laravel svn从win上传linux需要注意事项

    一首页设置目录权限: /storage  /bootstrap/cache 设置可写权限 二执行命令: php artisan key:generate

  6. 跟开涛学SpringMVC(4.1):Controller接口控制器详解(1)

    http://www.importnew.com/19397.html http://blog.csdn.net/u014607184/article/details/52074530 https:/ ...

  7. mac mysql忘记密码解决办法

    http://www.jb51.net/article/87580.htm http://blog.csdn.net/soft2buy/article/details/50223373

  8. Zen of Python(Python的19条哲学)

    The Zen of Python Beautiful is better than ugly. Explicit is better than implicit. Simple is better ...

  9. 两点C#的propertyGrid的使用心得【转】

    源文:http://www.cnblogs.com/bicker/p/3318934.html 最近接触C#的PropertyGrid比较多,得到了两个小心得记录一下. 第1点是关于控制Propert ...

  10. [MFC]选择目录对话框和选择文件对话框 [转]

      在MFC编程中经常会需要用到选择目录和选择文件的界面,以下总结一下本人常用的这两种对话框的生成方法: 选择目录对话框 {    char szPath[MAX_PATH];     //存放选择的 ...