time limit per test1 second

memory limit per test256 megabytes

inputstandard input

outputstandard 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.

【题目链接】:http://codeforces.com/contest/738/problem/C

【题解】



把每个gas station按照位置升序排;

把车按照v[i]升序排(c[i]不用管);

l = 1,r = n;

m = (l+r)>>1;

这个m作为当前枚举的车是什么;

注意到每次到车站之后油都能变满(哪个傻子不装满?免费的!)

它的容量作为从两个gas站之间的花费上限;

while(l<=r)
{
...
if (ok(m))
ans = m,r = m-1;
else
l = m+1;
}

那么ok函数要怎么写?

    bool ok(int w)
{
LL temp =0;
for (i = 1->k)
{
int ds = p[i]-p[i-1];
if (ds*2<=w)//使用加速模式花费汽油是距离的两倍
temp+=ds;//所用的时间就是距离;
else//不能全部使用加速模式
{//那就设低速模式x分钟,加速模式y分钟
/*
则有
0.5*x+y=ds ···①距离要恰好为两个站之间的距离
0.5x+2*y<=w ···②花费的燃油要小于等于油箱容量
显然要让y最大,这样时间最短;
而联立①②式可得
y<=w-ds;
所以y的最大值为w-ds;
相应的x = 2*(ds-y);
*/
if (w-ds>0)//如果能够有一段为加速模式
{
y = w-ds;
x = 2*(ds-y);
cost = y*2+x/2;
temp+=(x+y);//时间就是x+y;
}
else//只能全程为低速模式尝试一下
{
if (ds<=w)
temp+=2*ds;//时间为两倍距离
else
return false;
}
}
if (temp>t)//时间大于t了就返回false;
return false;
}
return true;
}

这样我们就把油箱容量符合要求的最小油箱容量的车的下标ans搞出来了;

之后枚举1->n,找到那些油箱容量大于等于这个ans车的容量的车;在它们之间找价格最低的;



【完整代码】

#include <bits/stdc++.h>
#define LL long long using namespace std; const int MAXNK = 2e5+10;
const LL INF = 1e18; struct abc
{
int c,v;
}; abc a[MAXNK];
int p[MAXNK];
int n,k,s;
LL t;
LL fi = INF; bool cmp1(abc a,abc b)
{
return a.v < b.v;
} bool ok(int w)
{
LL temp = 0;
for (int i = 1;i <= k;i++)
{
int cost = (p[i]-p[i-1])*2;
if (cost<=w)//直接全速前进
temp+=p[i]-p[i-1];
else
{//枚举在p[i-1]..p[i],前面用低速后面用高速;
int ds = p[i]-p[i-1];
int x,y;
if (w-ds>0)
{
y = w-ds;
x = 2*(ds-y);
cost = y*2+x/2;
temp+=(x+y);
/*
if (w==8)
{
puts("233");
cout << "ds==" << ds<<endl;
cout << "temp=="<<temp<<endl;
cout << "w-ds=="<<w-ds<<endl;
cout <<"cost=="<<cost<<endl;
cout << y<<endl;
cout << x<<endl;
}
*/
}
else
{
if (ds<=w)
temp+=2*ds;
else
return false;
}
}
if (temp > t)
return false;
}
return true;
} int main()
{
//freopen("F:\\rush.txt","r",stdin);
cin >> n >> k >>s >>t;
for (int i = 1;i <= n;i++)
scanf("%d%d",&a[i].c,&a[i].v);
p[0] = 0;
for (int i = 1;i <= k;i++)
scanf("%d",&p[i]);
sort(a+1,a+1+n,cmp1);
sort(p+1,p+1+k);
k++;
p[k] = s;
/*
for (int i = 1;i <= k;i++)
cout << p[i] << " ";
cout << endl;
*/
int l = 1,r = n,ans = -1;
while (l <= r)
{
int m = (l+r)>>1;
if (ok(a[m].v))
{
ans = m;
r = m-1;
}
else
l = m+1;
}
if (ans == -1)
{
puts("-1");
return 0;
}
//cout << ans << endl;
for (int i = 1;i <= n;i++)
{
if (a[i].v >= a[ans].v && a[i].c < fi)
fi = a[i].c;
}
cout << fi << endl;
//wujie -1
return 0;
}

【26.83%】【Codeforces Round #380C】Road to Cinema的更多相关文章

  1. 【57.97%】【codeforces Round #380A】Interview with Oleg

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  2. 【42.86%】【Codeforces Round #380D】Sea Battle

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  3. 【21.21%】【codeforces round 382D】Taxes

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  4. 【50.88%】【Codeforces round 382B】Urbanization

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  5. 【Codeforces Round 1137】Codeforces #545 (Div. 1)

    Codeforces Round 1137 这场比赛做了\(A\).\(B\),排名\(376\). 主要是\(A\)题做的时间又长又交了两次\(wa4\)的. 这两次错误的提交是因为我第一开始想的求 ...

  6. 【Codeforces Round 1132】Educational Round 61

    Codeforces Round 1132 这场比赛做了\(A\).\(B\).\(C\).\(F\)四题,排名\(89\). \(A\)题\(wa\)了一次,少考虑了一种情况 \(D\)题最后做出来 ...

  7. 【Codeforces Round 1120】Technocup 2019 Final Round (Div. 1)

    Codeforces Round 1120 这场比赛做了\(A\).\(C\)两题,排名\(73\). \(A\)题其实过的有点莫名其妙...就是我感觉好像能找到一个反例(现在发现我的算法是对的... ...

  8. 【Codeforces Round 1129】Alex Lopashev Thanks-Round (Div. 1)

    Codeforces Round 1129 这场模拟比赛做了\(A1\).\(A2\).\(B\).\(C\),\(Div.1\)排名40. \(A\)题是道贪心,可以考虑每一个站点是分开来的,把目的 ...

  9. 【Codeforces Round 1117】Educational Round 60

    Codeforces Round 1117 这场比赛做了\(A\).\(B\).\(C\).\(D\).\(E\),\(div.2\)排名\(31\),加上\(div.1\)排名\(64\). 主要是 ...

随机推荐

  1. wget---从指定的URL下载文件

    wget命令用来从指定的URL下载文件.wget非常稳定,它在带宽很窄的情况下和不稳定网络中有很强的适应性,如果是由于网络的原因下载失败,wget会不断的尝试,直到整个文件下载完毕.如果是服务器打断下 ...

  2. PythonOOP面向对象编程1

    什么是对象? 对象是指现实中的物体或实体(拥有一系列变量.函数(方法)的) 什么事面向对象? 把一切看成对象(实例),让对象和对象之间建立关联关系 对象都有什么特征? 属性(名词)实例变量 姓名.年龄 ...

  3. CSS3:元素的边框、背景和大小

    边框 和边框相关的属性例如以下. border-width 用于设置边框的宽度,可选择包含: 1)<长度值>:将边框宽度设为以CSS度量单位(如em.px.cm)表达的长度值. 2)< ...

  4. 根证书 CA

    根证书 CA 密钥没有密码,使用下面的指令添加密码 openssl rsa -aes256 -in cakey_nopw.pem -out cakey_pw.pem cacert.pem -----B ...

  5. 1.3 Quick Start中 Step 6: Setting up a multi-broker cluster官网剖析(博主推荐)

    不多说,直接上干货! 一切来源于官网 http://kafka.apache.org/documentation/ Step 6: Setting up a multi-broker cluster ...

  6. Spring源码分析专题 —— IOC容器启动过程(上篇)

    声明 1.建议先阅读<Spring源码分析专题 -- 阅读指引> 2.强烈建议阅读过程中要参照调用过程图,每篇都有其对应的调用过程图 3.写文不易,转载请标明出处 前言 关于 IOC 容器 ...

  7. codeforces 1037E. Trips(倒叙)

    题目传送门: 解题思路: 正着搞好像有点恶心. 反着搞. 一边删一边搞,从崩坏的地方开始,入度--. 最后dfs崩坏,更新答案. 注意要把边删掉防止重复崩坏. 代码: #include<cstd ...

  8. MariaDB 安装 (YUM)

    在CentOS 7.0安装MariaDB的数据库,在这里记录下安装过程,以便以后查看. 1. 安装MariaDB 安装命令 yum -y install mariadb mariadb-server ...

  9. PHP版本 D-Link 动态域名客户端

    <?php /* * D-Link 动态域名客户端.主域名www.dlinkddns.com 和 www.dlinkddns.com.cn * 首先获取外网IP,若IP没有变化,则结束运行:否则 ...

  10. Android学习笔记进阶十之Matrix错切变换

    刚开始我也不懂啥叫错切变换,一看效果图你就恍然大悟. 对图像的错切变换做个总结: x = x0 + b*y0; y = d*x0 + y0; 与之对应的方法是: Matrix matrix = new ...