Codeforces Round #380 (Div. 2)C. Road to Cinema

来源:互联网 发布:js 对象 remove 编辑:程序博客网 时间:2024/05/16 06:44
C. Road to Cinema
time limit per test
1 second
memory limit per test
256 megabytes

Vasya is currently at a car rental service, and he wants to reach cinema. The film he has bought a ticket for starts int minutes. There is a straight road of lengths from the service to the cinema. Let's introduce a coordinate system so that the car rental service is at the point0, 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 integersci andvi — 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 capacityvi. 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 covers1 kilometer in 2 minutes, and consumes1 liter of fuel. In the accelerated mode a car covers1 kilometer in 1 minutes, but consumes2 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 int minutes. Assume that all cars are completely fueled initially.

Input

The first line contains four positive integers n,k, s andt (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 integersci andvi (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 int minutes). If there is no appropriate car, print-1.

Examples
Input
3 1 8 1010 85 711 93
Output
10
Input
2 2 10 1810 420 65 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 to10, and the capacity of its fuel tank is 8. Then Vasya can drive to the first gas station in the accelerated mode in3 minutes, spending 6 liters of fuel. After that he can full the tank and cover2 kilometers in the normal mode in 4 minutes, spending 2 liters of fuel. Finally, he drives in the accelerated mode covering the remaining3 kilometers in 3 minutes and spending6 liters of fuel.


题意:

n,k,s,t(车的种数,加油站个数,路程,时限);

n行 c(i) v(i)  (每种车的 价格 和  汽油容量);

k行 g(i)      (每个加油站的位置);

两种行车方式 1km/h 耗油1L  或 1km/2h  耗油2L ;

如果不能在实现内到达,输出-1,否则输出最小的花费。


思路:二分查找行完全程所需的最小汽油容量,再枚举车的类型,求满足的最小花费。


#include <queue>#include <functional>#include <stdio.h>#include <string.h>#include <iostream>#include <algorithm>#include <stack>#include <vector>#include <set>#include <map>#include <string>#include <cmath>#include <cstdlib>#include <ctime>#include <assert.h>#define REP(i,k,n) for(int i=k;i<n;i++)#define REPP(i,k,n) for(int i=k;i<=n;i++)#define scan(d) scanf("%d",&d)#define scann(n,m) scanf("%d%d",&n,&m)#define mst(a,k)  memset(a,k,sizeof(a));#define LL long long#define eps 1e-8#define INF 0x3f3f3f3f#define mod 1000000007#define N 200005#define M 15#define fre  freopen("input.txt","r",stdin)#define upmo(a,b) (((a)=((a)+(b))%mo)<0?(a)+=mo:(a))using namespace std;struct no{   int c,v;}no[N];int n,k,s,t;int num[N];bool check(int x)                       // 判断改容量能否满足{   LL cot = 0;                          // 注意  可能超int   if(x>t) return 0;                  REPP(i,0,k){     if(x < num[i]) return 0;     if(x >= 2 * num[i]) cot += num[i];     else{      cot += num[i] * 2;      cot -= x - num[i];     }     if(cot > t) return 0;   }   return 1;}int main(){   scann(n,k); scann(s,t);   REP(i,0,n) scann(no[i].c,no[i].v);   REPP(i,1,k) scan(num[i]);   num[k+1] = s;   num[0] = 0;   sort(num,num+k+2);                       //注意 加油站要排序   REPP(i,0,k) num[i] = num[i+1] - num[i];   if(s > t) {      printf("-1");      return 0;   }   int l = 0, r = t + 2;   while(l <= r){      int mid = (l + r) >> 1;      if(check(mid)) r = mid - 1;      else   l = mid + 1;   }   int ans = INF;   REP(i,0,n){                                //枚举求最小花费   if(no[i].v <= r) continue;   ans = min(ans , no[i].c);   }   printf("%d",ans==INF?-1:ans);}






0 0