Test instructions: You will drive from 0 o'clock to S point, there are some gas stations on the road, refueling time is negligible. You have two driving options: 1min per km, 2L oil, and 2min per km, which costs 1L oil. You have n kinds of cars to choose from, give their fuel tank capacity (just start full) and price, whether to choose a car with the lowest price, can run the whole process within the time t. If not output-1
Problem solving: Direct two-part oil, the minimum amount of oil required .... Then choose the car, speed choice above a little thought can be out.
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's length s from the service to the cinema. Let's introduce a coordinate system so, the car rental service was at the point 0, and the cinema was at the point S.
There is K gas stations along the road, and at all them you can fill a car with any amount of fuel for free! Consider that this operation doesn ' t take any time, i.e. are carried out instantly.
There was n cars in the rental service, i-th of them was characterized with a 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 is completely fueled at the car rental service.
Each of the cars can is driven in one of the both speed modes:normal or accelerated. In the normal mode a car covers 1 kilometer in 2 minutes, and consumes 1 liter of fuel. 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 this vasya can reach the cinema before the show starts, i.e. not late R than in T minutes. Assume that all cars is 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 TI Me in which the film starts.
Each of the next n lines contains-positive integers ci and VI (1≤CI, vi≤109)-the price of the i-th car and its F Uel tank capacity.
The next line contains k distinct integers g1, G2, ..., GK (1≤gi≤s-1)-the positions of the gas stations on the ROA D in arbitrary order. Output
Print the minimum rent price of a appropriate car, i.e. such car that Vasya would be able to reach the cinema before the F ILM starts (not later than in T minutes). If there is no appropriate car, print-1. Example Input
3 1 8
8
5 7 each
9
3
Output
10
Input
2 2
4
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 is cheaper to Choo Se the first one. Its price is equal to ten, 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 this 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.
#include <bits/stdc++.h> using namespace std;
const int N = 2e5 + 100;
const int inf = 0X3F3F3F3F;
struct node {int c,v;} A[n];
int b[n],c[n];
int t,k,s;
int work1 (int v) {int i,j,sum;
sum=0;
for (i=0; i<=k; i++) {sum+=c[i]*2-min (v-c[i],c[i]);
} return sum;
} int work (int l,int r) {int mid,num;
while (l<=r) {mid= (l+r) >>1;
Num=work1 (mid);
if (num<=t) r=mid-1;
else l=mid+1;
} return L;
} int main () {int i,j,v,l,r,ans,n,tmp;
scanf ("%d%d%d%d", &n,&k,&s,&t);
for (I=1; i<=n; i++) scanf ("%d%d", &A[I].C,&A[I].V);
for (i=0; i<k; i++) scanf ("%d", &b[i]);
Sort (b,b+k);
C[0]=B[0];
for (I=1; i<k; i++) c[i]=b[i]-b[i-1];
C[K]=S-B[K-1];
l=0,r=0;
for (i=0; i<=k; i++) R+=c[i]*2,l=max (L,c[i]);
V=work (L,R);
Ans=inf;
for (I=1; i<=n; i++) {if (a[i].v>=v) ans=min (ANS,A[I].C); } if (Ans==inf ||
Work1 (v) >t) ans=-1;
printf ("%d\n", ans);
return 0;
}