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 2 minutes, 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 t minutes. Assume that all cars are completely fueled initially.

Input

The first line contains four positive integers n, k, s 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 3 minutes, spending 6 liters of fuel. After that he can full the tank and cover 2 kilometers in the normal mode in 4 minutes, spending 2 liters of fuel. Finally, he drives in the accelerated mode covering the remaining 3 kilometers in 3 minutes and spending 6 liters of fuel.

题意:

有n辆车,每辆车有租金和邮箱的容量,路上有k个加油站,道路总长s,要求在t时间内到达终点,问选哪辆车可以以最少的租金在规定时间内到达,加油站加油不要钱,最后一行给出加油站的位置。

代码:

 //直接找会在第31组样例TE,卡了好久。二分油箱,找到一个最小的油箱容量能够走完全程,汽车排序后找到第一个大于等于该容量的汽车即可
//二分啊,每次都想不清楚,写不对!
#include<bits\stdc++.h>
using namespace std;
struct Lu
{
int r,v;
}L[];
int com[];
int n,k,s,t;
bool cmp1(Lu x,Lu y)
{
return x.r<y.r;
}
bool cmp2(int x,int y)
{
return x<y;
}
int check(long long mid)
{
int m=,now=,st=t;
while(m<k)
{
if(com[m]-now>mid||com[m]-now>st)
return ;
long long tem=mid-(com[m]-now);//剩余多少油就说明可以有多少路高速行驶
if(tem>com[m]-now)
tem=com[m]-now;
st-=(tem+*(com[m]-now-tem));
now=com[m];
m++;
}
if(s-now>mid||s-now>st)
return ;
long long tem=mid-(s-now);
if(tem>s-now)
tem=s-now;
st-=(tem+*(s-now-tem));
if(st<) return ;
return ;
}
int main()
{
scanf("%d%d%d%d",&n,&k,&s,&t);
for(int i=;i<n;i++)
scanf("%d%d",&L[i].r,&L[i].v);
for(int i=;i<k;i++)
scanf("%d",&com[i]);
sort(L,L+n,cmp1);
sort(com,com+k,cmp2);
long long lef=,rig=,mid;
while(lef<=rig)
{
mid=(lef+rig)/;
if(check(mid))
rig=mid-;
else lef=mid+;
}
// cout<<rig+1<<endl;
int ans=-;
for(int i=;i<n;i++)
if(L[i].v>=rig+)
{
ans=L[i].r;
break;
}
printf("%d\n",ans);
return ;
}

CF2.C(二分贪心)的更多相关文章

  1. Codeforces Gym 100231B Intervals 线段树+二分+贪心

    Intervals 题目连接: http://codeforces.com/gym/100231/attachments Description 给你n个区间,告诉你每个区间内都有ci个数 然后你需要 ...

  2. 2016-2017 ACM-ICPC CHINA-Final Ice Cream Tower 二分+贪心

    /** 题目:2016-2017 ACM-ICPC CHINA-Final Ice Cream Tower 链接:http://codeforces.com/gym/101194 题意:给n个木块,堆 ...

  3. 【bzoj2097】[Usaco2010 Dec]Exercise 奶牛健美操 二分+贪心

    题目描述 Farmer John为了保持奶牛们的健康,让可怜的奶牛们不停在牧场之间 的小路上奔跑.这些奶牛的路径集合可以被表示成一个点集和一些连接 两个顶点的双向路,使得每对点之间恰好有一条简单路径. ...

  4. Codeforces_732D_(二分贪心)

    D. Exams time limit per test 1 second memory limit per test 256 megabytes input standard input outpu ...

  5. CF732D Exams 二分 贪心

    思路:二分+贪心 提交次数:10次以上 错因:刚开始以为二分(边界,$+1or-1$)写错了,调了半天,后来才发现是$ck()$写错了.开始只判了最后是否小于零,而应该中间一旦小于零就$return\ ...

  6. $CF949D\ Curfew$ 二分/贪心

    正解:二分/贪心 解题报告: 传送门$QwQ$ 首先这里是二分还是蛮显然的?考虑二分那个最大值,然后先保证一个老师是合法的再看另一个老师那里是否合法就成$QwQ$. 发现不太会搞这个合不合法的所以咕了 ...

  7. $bzoj2067\ szn$ 二分+贪心

    正解:二分+贪心 解题报告: 传送门$QwQ$ 题目大意就说有一棵树,然后要用若干条线覆盖所有边且不能重叠.问最少要用几条线,在用线最少的前提下最长的线最短是多长. 昂首先最少用多少条线这个还是蛮$e ...

  8. leetcode1552题解【二分+贪心】

    leetcode1552.两球之间的磁力 题目链接 算法 二分+贪心 时间复杂度O(nlogn + nlogm) 1.根据题意描述,我们需要将m个球放入到n个篮子中,根据题目中数据范围描述发现m &l ...

  9. Codeforces 732D [二分 ][贪心]

    /* 不要低头,不要放弃,不要气馁,不要慌张 题意: n天进行m科考试,每科考试需要a的复习时间,n天每天最多可以考一科.并且指定哪天考哪科. 注意考试那天不能复习. 问最少需要多少天可全部通过考试. ...

随机推荐

  1. 相机变换与Ray-Casting

    p { margin-bottom: 0.1in; direction: ltr; line-height: 120%; text-align: justify; orphans: 0; widows ...

  2. 不得不喷一下中控科技,ZKT,恶心的中控,售后技术和屎一样,半年不见人。

    要做一个指纹考勤机和后台通信写入到mysql.在淘宝看了好多款,于是决定用指纹考勤机w6.卖家当时说支持二次开发,给我发的sdk.于是买了一台测试.机器来了开始测试,使用发的demo不能使用,于是去中 ...

  3. qt5.5程序打包发布以及依赖【转】

    玩qt5也有一段时间了,惭愧的是一直没有好好的发布过程序,因为写的都是小程序没啥需要用到发布,而且qt也说不上很熟悉,本来打算到基本掌握qt之后再来研究研究怎么打包程序,最近晚上的空闲时间多了,闲着也 ...

  4. MFC 如何创建浏览文件夹的对话框

    如何创建浏览文件夹的对话框 如何创建浏览文件夹的对话框 CString CXXXXDlg::GetOpenfolderPath() { BROWSEINFO bi; ZeroMemory(&b ...

  5. JAVA的模式对话框和非模式对话框

    周末的时候,一位网友让我帮他把他的无模式对话框改成有模式对话框. 界面是由swing制作的,都是JFrame,我从来没有接触过swing编程.大致的代码还是看的懂,很多都和C#很相似. 然后就去查资料 ...

  6. for_each(c++11)

    http://www.cplusplus.com/reference/algorithm/for_each/ template<class InputIterator, class Functi ...

  7. [转]ubuntu 下无法启动chrome

    这很不爽,google了半天也不知道答案(搜索到要重装chrome,可是我怎么都卸载不干净.....),最终解决方法如下: -------------------------------------- ...

  8. 让Fiddler 直接抓取java程序的方法

    Fiddler官网给出的解决办法(见http://www.fiddler2.com/fiddler/help/hookup.asp#Q-JavaTraffic)是设置jvm参数,如 jre -Dpro ...

  9. TDD学习笔记【二】---单元测试简介

    大纲 Testing 的第一个切入点:单元测试. 本篇文章将针对单元测试进行简介,主要内容包含了5W: Why What Where Who When 而How 的部分,属于实现部分,将于下一篇文章介 ...

  10. sql基础大全