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站之间的花费上限;

  1. while(l<=r)
  2. {
  3. ...
  4. if (ok(m))
  5. ans = m,r = m-1;
  6. else
  7. l = m+1;
  8. }

那么ok函数要怎么写?

  1. bool ok(int w)
  2. {
  3. LL temp =0;
  4. for (i = 1->k)
  5. {
  6. int ds = p[i]-p[i-1];
  7. if (ds*2<=w)//使用加速模式花费汽油是距离的两倍
  8. temp+=ds;//所用的时间就是距离;
  9. else//不能全部使用加速模式
  10. {//那就设低速模式x分钟,加速模式y分钟
  11. /*
  12. 则有
  13. 0.5*x+y=ds ···①距离要恰好为两个站之间的距离
  14. 0.5x+2*y<=w ···②花费的燃油要小于等于油箱容量
  15. 显然要让y最大,这样时间最短;
  16. 而联立①②式可得
  17. y<=w-ds;
  18. 所以y的最大值为w-ds;
  19. 相应的x = 2*(ds-y);
  20. */
  21. if (w-ds>0)//如果能够有一段为加速模式
  22. {
  23. y = w-ds;
  24. x = 2*(ds-y);
  25. cost = y*2+x/2;
  26. temp+=(x+y);//时间就是x+y;
  27. }
  28. else//只能全程为低速模式尝试一下
  29. {
  30. if (ds<=w)
  31. temp+=2*ds;//时间为两倍距离
  32. else
  33. return false;
  34. }
  35. }
  36. if (temp>t)//时间大于t了就返回false;
  37. return false;
  38. }
  39. return true;
  40. }

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

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



【完整代码】

  1. #include <bits/stdc++.h>
  2. #define LL long long
  3. using namespace std;
  4. const int MAXNK = 2e5+10;
  5. const LL INF = 1e18;
  6. struct abc
  7. {
  8. int c,v;
  9. };
  10. abc a[MAXNK];
  11. int p[MAXNK];
  12. int n,k,s;
  13. LL t;
  14. LL fi = INF;
  15. bool cmp1(abc a,abc b)
  16. {
  17. return a.v < b.v;
  18. }
  19. bool ok(int w)
  20. {
  21. LL temp = 0;
  22. for (int i = 1;i <= k;i++)
  23. {
  24. int cost = (p[i]-p[i-1])*2;
  25. if (cost<=w)//直接全速前进
  26. temp+=p[i]-p[i-1];
  27. else
  28. {//枚举在p[i-1]..p[i],前面用低速后面用高速;
  29. int ds = p[i]-p[i-1];
  30. int x,y;
  31. if (w-ds>0)
  32. {
  33. y = w-ds;
  34. x = 2*(ds-y);
  35. cost = y*2+x/2;
  36. temp+=(x+y);
  37. /*
  38. if (w==8)
  39. {
  40. puts("233");
  41. cout << "ds==" << ds<<endl;
  42. cout << "temp=="<<temp<<endl;
  43. cout << "w-ds=="<<w-ds<<endl;
  44. cout <<"cost=="<<cost<<endl;
  45. cout << y<<endl;
  46. cout << x<<endl;
  47. }
  48. */
  49. }
  50. else
  51. {
  52. if (ds<=w)
  53. temp+=2*ds;
  54. else
  55. return false;
  56. }
  57. }
  58. if (temp > t)
  59. return false;
  60. }
  61. return true;
  62. }
  63. int main()
  64. {
  65. //freopen("F:\\rush.txt","r",stdin);
  66. cin >> n >> k >>s >>t;
  67. for (int i = 1;i <= n;i++)
  68. scanf("%d%d",&a[i].c,&a[i].v);
  69. p[0] = 0;
  70. for (int i = 1;i <= k;i++)
  71. scanf("%d",&p[i]);
  72. sort(a+1,a+1+n,cmp1);
  73. sort(p+1,p+1+k);
  74. k++;
  75. p[k] = s;
  76. /*
  77. for (int i = 1;i <= k;i++)
  78. cout << p[i] << " ";
  79. cout << endl;
  80. */
  81. int l = 1,r = n,ans = -1;
  82. while (l <= r)
  83. {
  84. int m = (l+r)>>1;
  85. if (ok(a[m].v))
  86. {
  87. ans = m;
  88. r = m-1;
  89. }
  90. else
  91. l = m+1;
  92. }
  93. if (ans == -1)
  94. {
  95. puts("-1");
  96. return 0;
  97. }
  98. //cout << ans << endl;
  99. for (int i = 1;i <= n;i++)
  100. {
  101. if (a[i].v >= a[ans].v && a[i].c < fi)
  102. fi = a[i].c;
  103. }
  104. cout << fi << endl;
  105. //wujie -1
  106. return 0;
  107. }

【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. netstat---显示Linux中网络系统的状态信息

    netstat命令用来打印Linux中网络系统的状态信息,可让你得知整个Linux系统的网络情况. 语法 netstat(选项) 选项 -a或--all:显示所有连线中的Socket: -A<网 ...

  2. Duboo入门示例(Idea开发环境)

    在学习Dubbo分布式框架时的官方入门例子,很有代表性.简单清晰. 有关Dubbo的概念.概述和简单的配置文件,可以看官方文档的简述 会很快对Duboo有个整体的概念. 准备工作: 下载示例,点击这里 ...

  3. 68.qq号索引结构体写入内存,并实现快速排序

    //两个步骤,第一步读取文件,并且初始化索引结构体,把初始化的索引结构体写入到文件,第二步,读取这个文件到索引结构体 //并对这个结构体进行快速排序,得到顺序的索引,再写入文件 #define _CR ...

  4. JavaScript的字符串、数组以及DOM操作总结

    (一)JavaScript字符串操作 JavaScript的字符串就是用' '或" "括起来的字符表示,日常的学习中有时候需要对字符串进行相关的操作.例如要获取字符串某个指定位置的 ...

  5. HDU3689 Infinite monkey theorem 无限猴子(字符串DP+KMP)

    题目描述: 大概的意思就是根据无限猴子定理,无限只猴子坐在打字机旁瞎敲,总有一个能敲出莎士比亚文集.现在给你一个打字机和一只猴子,打字机的每个按钮(共n个)上的字母及猴子按下这个按钮的概率已知,而且猴 ...

  6. 如何运行vue项目(维护他人的项目)

    假如你是个小白,在公司接手他人的项目,这个时候,该怎么将这个项目跑通? 前提: 首先,这个教程主要针对vue小白,并且不知道安装node.js环境的.言归正传,下面开始教程:在维护项目之前,需要把所有 ...

  7. Elasticsearch入门系列~通过Java一系列操作Elasticsearch

    Elasticsearch索引的创建.数据的增删该查操作 上一章节已经在Linux系统上安装Elasticsearch并且可以外网访问,这节主要通过Java代码操作Elasticsearch 1.创建 ...

  8. matlab 辅助函数 —— 文件下载与文件解压

    0. 可读性的提升 为了提升代码的交互友好性,可在代码执行一些耗时操作时,显示地输出一些文本信息,以显示进度: fprintf('Downloading xxfilename...\n') urlwr ...

  9. Windows Forms 窗体篇

    1,显示窗体 非模式: Form form = new Form(); form.Show(); 模式: Form form = new Form(); form.Show(); 2,拥有者窗体与附属 ...

  10. Docker---(2)为什么要用Docker

    原文:Docker---(2)为什么要用Docker 版权声明:欢迎转载,请标明出处,如有问题,欢迎指正!谢谢!微信:w1186355422 https://blog.csdn.net/weixin_ ...